我有以下代码连接到sql server精简版2008:
I have the following code to connect to a sql server compact edition 2008:
private SqlConnection sqlConn; public void createConnection() { String connectionString = @"Data Source=C:\Projects\somefile.sdf;Persist Security Info=False"; sqlConn = new SqlConnection(connectionString); sqlConn.Open(); }但是,当 sqlConn时,我不断收到以下错误消息.open()被执行:
与网络相关或与实例相关的错误建立与SQL 服务器的连接时发生。找不到服务器或无法访问。验证实例名称正确并且SQL 服务器配置为允许远程连接。(提供者:SQL Network 接口,错误:26-错误定位指定的服务器/实例)
"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)"
是否有人知道问题可能是什么?我可以在数据库浏览器中创建到db的连接,但似乎无法在代码中使用。
Does anyone have any ideas what the problem might be? I can create a connection to the db in the database explorer but it doesn't seem to work in code.
推荐答案System.Data.SqlClient 中的code> Sql * 类只能用于连接到常规SQL Server实例。
The Sql* classes in System.Data.SqlClient can only be used to connect to a regular SQL Server instance.
要连接到SQL CE数据库,您需要创建一个 System.Data.SqlServerCe.dll $ c $中的 SqlCeConnection 对象 c>。
To connect to a SQL CE database, you need to create a SqlCeConnection object in System.Data.SqlServerCe.dll.
更多推荐
SQL Compact 2008连接字符串问题
发布评论