0

The following code gives an error during execution.

string connectionString = "Data Source=D:\\Base.sdf;Persist Security Info=False";
SqlConnection sqlConnection = new SqlConnection(connectionString)) 
sqlConnection.Open();

The error is:

A network-related or instance-specific error occured 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 not configured to allow remote connections. (provider:SQL network Interfaces, error: 26 - Error locating Server/Instance Specified)

I tried SqlCeConnection instead of SqlConnection but, the compiler couldn't find the library with that class.

Please, help to solve this problem.

  • The OS : Windows 7
  • Tool : Microsoft Visual Studio 2010
  • Language : C#
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nurlan
  • 2,860
  • 19
  • 47
  • 64
  • 4
    `.sdf` is **definitely** a SQL Server **Compact Edition** (CE) database - so you'll need to make sure you have the necessary assemblies installed in order for `SqlCeConnection` to work. This will **NOT** work with `SqlConnection` ! – marc_s Aug 28 '12 at 10:19
  • What assemblies do I need to install? – Nurlan Aug 28 '12 at 10:21
  • 1
    You need the SQL Server CE runtime stuff - check out [Everything SQL Server Compact](http://erikej.blogspot.ch/) - this site has tons of explanations, tutorials, how-tos etc. and will definitely also have the info on what needs to be installed and where to get it from – marc_s Aug 28 '12 at 10:23

1 Answers1

5

Your database is a Sql Server compact edition one, you must use :

SqlCeConnection sqlConnection = new SqlCeConnection(connectionString);

Download the libs from here Microsoft SQL Server Compact 4.0

  1. Add a reference to System.Data.SqlServerCe.dll to your project
  2. Add this using directive using System.Data.SqlServerCe;
  3. Use SqlCeConnection instead of SqlConnection
Nasreddine
  • 36,610
  • 17
  • 75
  • 94