Click here to Skip to main content
15,914,160 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
I create app that use SQL Server File Database (.mdf) file that is located in my project folder.App is working perfectly when i am on my PC but when i try to use at on other PC i get error that patch is wrong.So is there any why to make my Connection string auto generated to Project Folder or any other why.

What I have tried:

This is my string:

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\PC\Desktop\Projects\DApp\Database.mdf;Integrated Security=True;Connect Timeout=30");
Posted
Updated 12-Jun-18 3:11am

You should not hard code the path to the database, but put it in a directory intended for user data. Have a look at this excellent article[^] to help choose one.
 
Share this answer
 
Comments
Maciej Los 12-Jun-18 9:15am    
Sorry, but the main problem is that - that connection string refers to MS SQL Server installed on developement computer. Please, see my answer.
[no name] 12-Jun-18 9:20am    
It's referring to a local database in a file, and in the working example it's in the user's desktop directory. I'm not sure I follow you in the assumption that it's meant to be a shared database?
Maciej Los 12-Jun-18 9:24am    
No. I mean, OP have to enable remote connections to MS SQL Server to be able to "share" database between clients.
[no name] 12-Jun-18 9:25am    
If the clients don't have MS SQL Server installed, yes.
Maciej Los 12-Jun-18 9:28am    
Why to write database application if there's no way to share data between clients?
C#
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\PC\Desktop\Projects\DApp\Database.mdf;Integrated Security=True;Connect Timeout=30");

It won't work, because it refers to MS SQL server installed on developement computer...

If you would like to share database in LAN, you have to enable remote connections for MS SQL Server. For futher details, please see: Configure the remote access Server Configuration Option | Microsoft Docs[^]

Then you have to change connection string[^].

Imagine, you're the one who has access to that SQL Server instance till enable remote connections. In other words, SQL server have to broadcast its existence in a LAN ;)
 
Share this answer
 
v2

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