【发布时间】:2015-01-16 19:32:42
【问题描述】:
我编写了一个 C# Windows 窗体应用程序,它应该与 SQL Server 数据库 进行通信。我已经设置了连接字符串并且程序在我的系统中运行良好,而其他程序在连接到其他系统中的数据库时失败。
由于此应用程序将安装在客户的 PC 中。我该如何解决这个问题?
我尝试的最后一种方法是将 ConnectionString 添加到项目的 config 文件中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="con"
connectionString="Data Source=2345pc037\SQLEXPRESS;Initial Catalog=prodDB;Integrated Security=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
这里是 C# 代码:
SqlConnection cs = new SqlConnection();
strConn = string.Format({0}",ConfigurationManager.ConnectionStrings["con"].ConnectionString);
cs.ConnectionString = strConn;
错误消息指出实例名称不正确或 SQL Server 不允许远程连接。另外:“错误:28 - 服务器不支持请求的协议。”
【问题讨论】:
-
为什么不去看看这个网站,它非常有用C# Connectiong Strings to Databases 还有你的
strConn =string.Format({0}"` 不正确应该是strConn = string.format("{0}", ConfigurationManager.ConnectionStrings["con"].ConnectionString);connectionString="Data Source=2345pc037\SQLEXPRESS;是问题所在好 -
看看this。这不是连接字符串的问题。
标签: c# visual-studio-2012 sql-server-2012 windows-8.1 connection-string