0

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 2

2

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).

Sign up to request clarification or add additional context in comments.

2 Comments

How can i use database over network? Is there any way that i can use database on one PC and connect to it from other PC over network?
To run this on another PC, that PC must have SQL Server Express edition installed.
0

You need SQL Server Express to connect to database files. You have this installed automatically with visual studio, but another computer may not have it. Make sure that another computer has SQL server installed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.