我正在使用configurationmanager.appsetting
,并且在cn.Open
行中出现错误。无法连接到asp.net中的SQL Server数据库
Web表单代码如下:
public partial class admin_CheckDocuments : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["con"]);
string sql;
string str;
protected void Page_Load(object sender, EventArgs e)
{
cn.Open();
str = Request.QueryString["taxid"];
if (!IsPostBack)
{
filldata();
}
}
web.config
是:
<configuration>
<connectionStrings/>
<appSettings>
<add key="con"
value="Data Source=EGGG\SKDB;Initial Catalog=tax;Integrated Security=true"/>
</appSettings>
的错误是
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)
什么是错误? – Robert
错误是{“建立与SQL Server的连接时发生网络相关或实例特定的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供程序:SQL网络接口,错误:26 - 定位服务器/实例指定的错误)“} – sisodia1991
@ user1792379您是否有一个运行Sql Server的本地实例或一个在指定位置(EGGG \ SKDB)运行的实例? – Robert