[英]Visual Studio 2008 (C#) with SQL Compact Edition database error: 26
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
建立与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.
验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
(提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)
I've created a SQL compact database, included it in my application, and can connect to the database fine from other database editors, but within my application im trying 我已经创建了一个SQL压缩数据库,将其包含在我的应用程序中,并且可以从其他数据库编辑器连接到数据库,但在我的应用程序中我正在尝试
using (SqlConnection con = new SqlConnection(Properties.Settings.Default.DatabaseConnection))
{
con.Open();
}
the connection string is 连接字符串是
Data Source=|DataDirectory|\\Database.sdf
数据源= | DataDirectory | \\ Database.sdf
I'm stumped, any insight? 我很难过,有什么见解吗?
You're using the wrong type of connection object. 您正在使用错误类型的连接对象。 SqlConnection is for the grown up SQL server, not for SQL Server Compact.
SqlConnection适用于成熟的SQL服务器,而不适用于SQL Server Compact。
connectionstrings.com has the connection strings you need. connectionstrings.com具有您需要的连接字符串。 For the connection object itself I believe you need the SqlCeconnection class
对于连接对象本身,我相信你需要SqlCeconnection类
use SqlCeConnection
instead of SqlConnection
, include the namespace System.Data.SqlServerCe
instead of System.Data.SqlServer
. 使用
SqlCeConnection
而不是SqlConnection
,包括命名空间System.Data.SqlServerCe
而不是System.Data.SqlServer
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.