为什么在Vs2012运行期间会出现此错误? [英] Why Do I Keep Getting This Error During Runtime In Vs2012?

查看:86
本文介绍了为什么在Vs2012运行期间会出现此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切似乎都很完美,我输入的代码与在youtube ADO.net教程中说明的

完全相同 - >

https://www.youtube.com/watch?v=aoFDyt8oG0k [ Kudvenkat ^ ]





 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data.SqlClient;
使用 System.Data.Sql;
public partial class Default2 :System.Web.UI.Page
{
protected void Page_Load(< span class =code-keyword> object sender,EventArgs e)
{
SqlConnection con = new SqlConnection( data source =。;
database = sample; integrated security = SSPI
);
SqlCommand cmd = new SqlCommand( 选择*来自学生,con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
con.Close();
}
}





但是在浏览器中运行相同的代码时,我遇到了错误


建立与SQL Server的连接时发生与网络相关或特定于实例的错误。未找到服务器或无法访问
。实例名称是正确的并且
SQL Server配置为允许远程连接。(提供者:命名为
管道提供者,错误:40 - 无法打开与SQL
服务器的连接)指向con.open(); ./ <$ pre>

关于连接我在SERVER EXPLORER中连接了paricular数据库>

对此有什么补救措施?

解决方案

这是一个非常常见的问题,有很多潜在的原因,如:

- 防火墙

- 服务下来

- 未指定实例名称等等。



请通过http://www.sqlmusings.com/2009 / 03/11 /解决与网络相关或特定于实例的错误 - 同时建立连接到sql-server / [ ^ ]


 SqlConnection con = new SqlConnection (@data source =。; 
database = sample;集成安全性= SSPI);



在连接字符串之前只是前缀@并且它已经解决了!


这里的问题是你的应用程序不是能够连接到数据库..由于错误的凭据或不正确的连接字符串...打开连接时必须显示错误...

请尝试此连接字符串...

 Server = myServerAddress; Database = myDataBase; User Id = myUsername; 
Password = myPassword;



you也可以从这里获得适当的连接字符串。 [ ^ ]



如果这解决了您的问题,请投票并标记此作为解决方案..谢谢..


Everything seems to be perfect and i typed in the very same code as
illustrated in a youtube ADO.net tutorial ->
https://www.youtube.com/watch?v=aoFDyt8oG0k[^]
by Kudvenkat.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("data source=.;
database=sample ; integrated security=SSPI");
        SqlCommand cmd = new SqlCommand("Select *from student", con);
        con.Open();
        SqlDataReader rdr = cmd.ExecuteReader();
        GridView1.DataSource = rdr;
        GridView1.DataBind();
        con.Close();
    }
}



But while running the same code in browser ,i encounter an error

"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: Named
Pipes Provider, error: 40 - Could not open a connection to SQL
Server)" pointing to con.open(); line.


Regarding connection I have connected the paricular database in SERVER EXPLORER>
What is the Remedy for this ?

解决方案

This is a very common problem and there are a lot of potential reasons like:
- firewall
- service down
- instance name not specified and so on.

Please go through http://www.sqlmusings.com/2009/03/11/resolving-a-network-related-or-instance-specific-error-occurred-while-establishing-a-connection-to-sql-server/[^]


SqlConnection con = new SqlConnection(@"data source=.;
database=sample ; integrated security=SSPI");


just prefixed @ before connectionstring and it solved!


The problem here is your application is not been able to connect to database.. due to wrong credentials or improper connection string... The error must be showing while opening the connection...
Please try this connection string...

Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;


you can also get appropriate connection string from here.[^]

If this solves your issue kindly up vote and mark this as solution.. Thanks..


这篇关于为什么在Vs2012运行期间会出现此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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