asp.net中的sqlconnection设置错误 [英] sqlconnection setting error in asp.net

查看:84
本文介绍了asp.net中的sqlconnection设置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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









如何清除此错误请帮助我

解决方案

首先为什么你不分享你的连接字符串?





Windows身份验证中的Sql连接字符串。你可以随意改变。像那样

 SqlConnection con =  new  SqlConnection( 数据源=您的用户名,或者您可以尝试。[dot];初始目录=数据库名称;集成安全性=真;池化=假 );  





Sql Server身份验证。



< connectionstrings> 

< add name = MyDbConn >
connectionString = < span class =code-string> Server = MyServer;数据库=酒吧;用户ID = MyUser; password = P @ ssw0rd
providerName = System.Data.SqlClient />
< / add > < / connectionstrings >





更多信息点击此链接 http://msdn.microsoft.com/en-us/library/ff648340.aspx



任何查询点击回复。


在web.config页面中的





 <  配置 >  
< span class =code-keyword>< connectionStrings >
< add 名称 = mycon connectionString = data source = Data Source = .\SQLEXPRESS; AttachDbFilename = D:\sponsorship project \sponsorship.mdf; Integrated Security = True; Connect Timeout = 30; User Instance = True providerName = System.Data.SqlClient / >
< / connectionStrings >
< span class =code-key单词>< system.web >
< 编译 debug = true targetFramework = 4.0 < span class =code-keyword> / >
< 身份验证 mode = 表格 >

< br $>




和aspx页面



  protected   void  Button1_Click( object  sender,EventArgs e)
{
string connect = ConfigurationManager.ConnectionStrings [ mycon]的ConnectionString。

SqlConnection con = new SqlConnection(connect);
cmd.Connection = con;


基本上,当你无法连接到SQL Server时,问题可能是:

1)网络问题,
2)SQL Server配置问题。

3)防火墙问题,

4)客户端驱动程序问题,

5)应用程序配置问题。

6)身份验证和登录问题。

检查这些

解决SQL连接问题的步骤 [ ^ ]

SQL Server 2005连接问题疑难解答 - 第一部分 [ ^ ]

连接问题疑难解答在SQL Server 2005 - 第二部分 [ ^ ]

解决SQL Server 2005中的连接问题 - 第III部分 [ ^ ]

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)




how can i clear this error please help me out

解决方案

First of all why you not share your connection string in question?


Sql Connection string in Windows Authentication. you can change as you want. like that

SqlConnection con= new SqlConnection("Data Source=your User Name or you can try .[dot];Initial Catalog=Database Name;Integrated" Security=True;Pooling=False");



Sql Server Authentication.

<connectionstrings>

  <add name="MyDbConn">
       connectionString="Server=MyServer; Database=pubs; User Id=MyUser; password= P@ssw0rd"
       providerName="System.Data.SqlClient" />
</add></connectionstrings>



for more information hit this link http://msdn.microsoft.com/en-us/library/ff648340.aspx

any query hit to reply.


in web.config page

<configuration>
  <connectionStrings>
    <add name="mycon" connectionString="data source=Data Source=.\SQLEXPRESS;AttachDbFilename=D:\sponsorship project\sponsorship.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <authentication mode="Forms">




and in aspx page

protected void Button1_Click(object sender, EventArgs e)
   {
       string connect = ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;

       SqlConnection con = new SqlConnection(connect);
       cmd.Connection = con;


Basically, when you failed to connect to your SQL Server, the issue could be:
1) Network issue,
2) SQL Server configuration issue.
3) Firewall issue,
4) Client driver issue,
5) Application configuration issue.
6) Authentication and logon issue.

Check these
Steps to troubleshoot SQL connectivity issues[^]
SQL Server 2005 Connectivity Issue Troubleshoot - Part I[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part II[^]
Troubleshoot Connectivity Issue in SQL Server 2005 - Part III[^]


这篇关于asp.net中的sqlconnection设置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆