I have a problem, I made a nice application in C# with a SQL database, now I wanted to install that application on another pc but it doesn't connect to database file. Is there a nice way that I can install that database and connect to it with only changing connection string in my program. Is there any way that I can access the database through network? I tried to find some tutorial but without luck..
2 Answers
I would suggest you to append the database file (which ever it is) to your project. So it will be located inside the project`s folder. But before Publishing the application, change the connection string, instead of a full path use |DataDirectory| . This is an example:
//from
@"....Database=C:\MyProject\MyDataBase.mdf;...";
//change to to:
@"....Database=|DataDirectory|\MyDataBase.mdf;...";
This way you will not have issues with connection string. But dont forget to ADD the database file to your project (incuse it in it).