Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<pre lang="c#">        static string domain = (AppDomain.CurrentDomain.BaseDirectory).ToString();
        internal static string connect = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename= "+domain+"BMS_PRO_DB.mdf;" + "Integrated Security=True;Connect Timeout=30;";


the database is inside the app's location,
i think my connection is wrong thats why the app is working fine on my server but on the other PC(SQL Server is installed in this pc too) its not working.

What I have tried:

please help, im getting the error : sql not found or not accessible ...
Posted
Updated 28-Dec-17 21:38pm

One word: DEBUGGER. Learn to use it and it'll become obvious what you did wrong.

You're doing some goofy things and not account for spaces in the path you generated.

For example, why are you calling .ToString() on a string returned by BaseDirectory? That's just ....

The connection string should be stored in the config file, not as a hardcoded value in your code. What if the user doesn't what to use LocalDB and instead has either SQL Server Express or a full SQL Server somewhere? They can't use your code because it's too inflexible.

Also, the code is (hopefully!) going to be running from somewhere under C:\Program Files. Program Files, and everything under it, is READ ONLY. That's not the place you want to be putting your database. I suggest placing it somewhere more appropriate, like in a folder under ProgramData, where normal users have write permissions.
 
Share this answer
 
Yes, your connection is wrong. When the code runs on the other computer it will try to access a sql server at (LocalDB) so if the local computer does not have sql, it will not work. Change it to the name of the sqlserver machine or ip address so it can connect.
 
Share this answer
 
HappyFestivus, give me an example , also tell me that , do i need to get the code of machine on which app is running, i dont get that.
 
Share this answer
 
Comments
Patrice T 29-Dec-17 3:40am    
Do not use a solution to discuss with someone else.
Use 'Have a Question or Comment?' button instead, advantage, the OP is noticed.
Quote:
do i need to get the code of machine on which app is running, i dont get that.

Looks like you need to learn the basics of SQL.

You need to install an SQL engine and your database on a server in your network.
Then change your app to refer to the database.
Internet is loaded with examples and tutorials, you just have to do a little search.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900