SQL Server Compact Edition 4.0: Error: 26 - Server / Instance Location Error

I am developing a console application (C # /. Net Framework 4.0 / VS2012). I created the SQL Server Compact database ( *.sdf ) and added the connection string as:

 <connectionStrings> <add name="Dispatcher.Properties.Settings.FakeDataSetConnectionString" connectionString="Data Source=|DataDirectory|\FakeDataSet.sdf" providerName="Microsoft.SqlServerCe.Client.4.0" /> </connectionStrings> 

But when I try to execute the following code:

 SqlConnection con = new SqlConnection(); con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dispatcher.Properties.Settings.FakeDataSetConnectionString"].ToString(); con.Open(); 

This gives the following exception in con.Open ():

When connecting to SQL Server, a network-related or specific instance error occurred. The server was not found or was not available. Verify the instance name is correct and configure SQL Server to connect remotely. (provider: SQL network interfaces, error: 26 - server / instance location error)

  • What am I doing wrong here?

  • SQL Server Agent and SQL Server Browser are in the Start state. Does it really matter when using SQL Server Compact Edition?

+4
source share
1 answer

For SQL Server Compact you need to use SqlCeConnection ( not SqlConnection ), which is for the "real" versions of SQL Server).

 SqlCeConnection con = new SqlCeConnection(); con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dispatcher.Properties.Settings.FakeDataSetConnectionString"].ToString(); con.Open(); 

And, of course, you will also need to use SqlCeCommand (not SqlCommand ) and so on ...

For more information on all classes in the System.Data.SqlServerCe namespace, see the MSDN SQL Server System.Data.SqlServerCe Documentation .

+6
source

Source: https://habr.com/ru/post/1483955/


All Articles