Click here to Skip to main content
14,266,139 members
Rate this:
Please Sign up or sign in to vote.
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
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

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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100