Nurlan
Nurlan

Reputation: 2960

Error in connection to database

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.

Upvotes: 0

Views: 326

Answers (1)

Nasreddine
Nasreddine

Reputation: 37858

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

Upvotes: 5

Related Questions