Error en la conexión a la base de datos

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();

El error es:

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)

Lo intenté SqlCeConnection en lugar de SqlConnection but, the compiler couldn't find the library with that class.

Por favor, ayude a resolver este problema.

  • The OS : Windows 7
  • Tool : Microsoft Visual Studio 2010
  • Idioma: C #

preguntado el 28 de agosto de 12 a las 11:08

.sdf is que probar definitivamente a SQL Server Edición compacta (CE) database - so you'll need to make sure you have the necessary assemblies installed in order for SqlCeConnection to work. This will NO trabajar con SqlConnection ! -

What assemblies do I need to install? -

You need the SQL Server CE runtime stuff - check out Todo SQL Server Compact - 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 -

1 Respuestas

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 compacto 4.0

  1. Agregar una referencia a System.Data.SqlServerCe.dll a tu proyecto
  2. Add this using directive using System.Data.SqlServerCe;
  3. Utilice las SqlCeConnection en lugar de SqlConnection

Respondido 28 ago 12, 11:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.