I have been developing a console application (C# / .Net Framework 4.0 / VS2012). I created a SQL Server Compact database (*.sdf
) and added a 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'm trying to execute the following code:
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dispatcher.Properties.Settings.FakeDataSetConnectionString"].ToString();
con.Open();
It gives the following exception at con.Open():
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)
What I'm doing wrong here?
SQL Server Agent and SQL Server Browser are both in "Started" Status. Does it actually matter when using SQL Server Compact Edition?
For SQL Server Compact, you need to use SqlCeConnection
(not SqlConnection
- that's for the "real" SQL Server versions).
SqlCeConnection con = new SqlCeConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dispatcher.Properties.Settings.FakeDataSetConnectionString"].ToString();
con.Open();
And of course, you'll also need to use SqlCeCommand
(not SqlCommand
) and so on...
See the MSDN SQL Server Books Online documentation for more details on all the classes in the System.Data.SqlServerCe
namespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With