简体   繁体   English

Visual Studio 2008(C#)与SQL Compact Edition数据库错误:26

[英]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

See this article for an example 请参阅此文章以获取示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Visual Studio 2010 C#访问sql 2008数据库 - Accessing sql 2008 database through visual studio 2010 C# 如何在Visual Studio C#2008 Express Edition中将C#文件与数据库一起发送到一个zip文件中? - How do I send a C# file in Visual Studio C# 2008 express edition along with the database in one zip file? SQL Compact Edition插入C# - SQL Compact Edition Insert C# SQL错误26 Visual Studio - SQL error 26 visual studio 在Visual Studio 2010 C#中不允许访问数据库文件(SQL Server Compact) - Access to database file not allowed (SQL Server Compact) in Visual Studio 2010 C# .NET C#Visual Studio 2008错误 - .Net c# visual studio 2008 error 在Visual Studio 2013中使用SqlCeResultSet进行SQL Server Compact Edition数据访问 - SQL Server Compact Edition Data Access with the SqlCeResultSet in Visual Studio 2013 如何在C#中将SQL Server Compact Edition数据库连接到Crystal Report - How to connect SQL Server Compact Edition database to Crystal Report in C# 为什么我不能用C#将数据插入本地数据库(SQL Compact Edition)? - Why can't I insert data into local database (SQL Compact Edition) with C#? SQL Server Compact Edition 4.0:错误:26 - 找到指定的服务器/实例时出错 - SQL Server Compact Edition 4.0: Error: 26 - Error Locating Server/Instance Specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM