本文介绍了SQL Server Compact Edition 4.0:错误:26 - 定位指定的服务器/实例时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个控制台应用程序(C#/.Net Framework 4.0/VS2012).我创建了一个 SQL Server Compact 数据库 (*.sdf) 并添加了一个连接字符串:

I have been developing a console application (C# / .Net Framework 4.0 / VS2012). I created a SQL Server Compact database (*.sdf) and added a connection string as:

<connectionStrings>
    <add name="Dispatcher.Properties.Settings.FakeDataSetConnectionString"
        connectionString="Data Source=|DataDirectory|\FakeDataSet.sdf"
        providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>

但是当我尝试执行以下代码时:

But When I'm trying to execute the following code:

SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dispatcher.Properties.Settings.FakeDataSetConnectionString"].ToString();
con.Open();

它在 con.Open() 给出以下异常:

It gives the following exception at con.Open():

与 SQL Server 建立连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接.(提供程序:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)

  1. 我在这里做错了什么?

  1. What I'm doing wrong here?

SQL Server 代理和 SQL Server 浏览器都处于已启动"状态.使用 SQL Server Compact Edition 真的很重要吗?

SQL Server Agent and SQL Server Browser are both in "Started" Status. Does it actually matter when using SQL Server Compact Edition?

推荐答案

对于SQL Server Compact,需要使用SqlCeConnection(SqlConnection - 这适用于真正的"SQL Server 版本).

For SQL Server Compact, you need to use SqlCeConnection (not SqlConnection - that's for the "real" SQL Server versions).

SqlCeConnection con = new SqlCeConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dispatcher.Properties.Settings.FakeDataSetConnectionString"].ToString();
con.Open();

当然,您还需要使用 SqlCeCommand(不是 SqlCommand)等等...

And of course, you'll also need to use SqlCeCommand (not SqlCommand) and so on...

请参阅 MSDN SQL服务器联机丛书文档,了解有关 System.Data.SqlServerCe 命名空间

See the MSDN SQL Server Books Online documentation for more details on all the classes in the System.Data.SqlServerCe namespace

这篇关于SQL Server Compact Edition 4.0:错误:26 - 定位指定的服务器/实例时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:40