Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program stores the data in the database created on the Visual studio 2012 Everything works fine on a my PC question is how should I connect to the database if I want to open the program from another computer? I tried copying the program on a friend's computer but it cannot find the database program stop work

This is the connection string
C#
SqlCeConnection con = new SqlCeConnection("Data Source=H:\\apps\\application.sdf");


So I change connection string like this
Get the application run path because DB is in the application folder

C#
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
SqlCeConnection con = new SqlCeConnection(""@ Data Source =" + appPath + "\application.sdf");



No error No stuck in but still not connect
I'm new to C# I think this is a stupid way to do this
How to do this
Thank in Advance
Posted

1 solution

Make sure the *.sdf file is available in the specified location after compiling your solution. Check the property of the *.sdf , you may have to copy if it's newer.
 
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