Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have developed a desktop application but there is Local Based Server means .sdf file as a database. When I want to connect through:

I have connection in APP.config file and

SqlConnectionstring con=new sqlConnection()
con.Open()

This got an network related error message:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)".

How to connect to Local based server? How to Solve this Problem?
Posted
Updated 7-Mar-13 5:32am
v6
Comments
joshrduncan2012 7-Mar-13 10:45am    
You need to tag your posts correctly. There is a tag for Sql Server Compact Edition (which are the .sdf files).

Also, you are creating a connection, but not pointing to the .sdf file, so the compiler doesn't know where the .sdf file is located to connect to.
Shafiqur Rahman, Banladesh 7-Mar-13 10:58am    
I have appconfig file and I have debug and found connectionstring (location of sdf file) in debugging mode.

You must put the ConnectionString into the SQLCEConnection object before you Open the connection.


See
SQLCEConnection Constructor
[^] for an example.

Example of how to retrieve ConnectionString by Name
Example: Retrieving a Connection String by Name[^]

Other documentation about getting ConnectionString from config file
Configuration.ConnectionStrings Property [^]
Configuration.AppSettings Property[^](Obsolete)
 
Share this answer
 
v5
The above code would not even compile (your class types are wrong), and you are missing the actual connection string; your code should be something like:
C#
SqlCeConnection con = new SqlCeConnection(Properties.Settings.Default.DBConnection);
con.Open();
 
Share this answer
 
Comments
Mike Meinz 7-Mar-13 13:19pm    
My 5 and Thanks for pointing out SQLCEConnection should be used. I changed Solution 1 to use SQLCEConnection.

BTW. The syntax for the SQLCEConnection Constructor allows no parameters. See SQL CEConnection Constructor
Richard MacCutchan 7-Mar-13 13:30pm    
Richard MacCutchan 7-Mar-13 13:30pm    
Oops, forgot to say thanks for the vote.

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