为什么我会收到此错误?错误在于我的代码吗? [英] Why do I recevie this error? Does the error lies in my code?

查看:74
本文介绍了为什么我会收到此错误?错误在于我的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

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



  namespace  ExportDataTableApplication 
{
class ExportDataTable
{
DateTime datetime = DateTime.Now ;

静态 void Main( string [] args)
{
Console.WriteLine( Running App );

DataSet ds = new DataSet();
DateTime datetime = DateTime.Now;
bool exception = false ;

string connString = string .Format( data source = {0}; initial catalog = {1}; Integrated Security = {2}; Connection Timeout = {3}
ConfigurationManager.AppSettings [ DataSource],
ConfigurationManager.AppSettings [ InitialCatalog],
ConfigurationManager.AppSettings [ IntegratedSecurity],
ConfigurationManager.AppSettings [ 超时]);

使用(SqlConnection conn = new SqlConnection(connString))
{

尝试 // 调用存储过程
{

SqlCommand sqlComm = new SqlCommand( dbo.Test,conn);

sqlComm.CommandType = CommandType.StoredProcedure;

SqlDataAdapter da = new SqlDataAdapter(sqlComm);

da.Fill(ds);
}

解决方案

尝试以下

解析无法打开与SQL Server错误的连接 [ ^ ]

SQL SERVER - FIX:ERROR :(提供者:命名管道提供者,错误:40 - 可能不打开与SQL Server的连接)(Microsoft SQL Server,错误:) [ ^ ]


在您的连接中找不到网络连接......



初始目录=在数据库连接名称中,如db name



string connString = string.Format(data source = {0}; 初始目录= {1}; Integrated Security = {2};连接超时= {3},









它可以帮到你..

Error:
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)

namespace ExportDataTableApplication
{
    class ExportDataTable
    {
        DateTime datetime = DateTime.Now;

        static void Main(string[] args) 
        {
            Console.WriteLine("Running App");

            DataSet ds = new DataSet();
            DateTime datetime = DateTime.Now;
            bool exception= false;

            string connString = string.Format("data source={0}; initial catalog={1}; Integrated Security ={2}; Connection Timeout={3}",
                       ConfigurationManager.AppSettings["DataSource"],
                       ConfigurationManager.AppSettings["InitialCatalog"],
                       ConfigurationManager.AppSettings["IntegratedSecurity"],
                       ConfigurationManager.AppSettings["TimeOut"]);

            using (SqlConnection conn = new SqlConnection(connString))
            {

                try //Call stored procedure
                {

                    SqlCommand sqlComm = new SqlCommand("dbo.Test", conn);

                    sqlComm.CommandType = CommandType.StoredProcedure;

                    SqlDataAdapter da = new SqlDataAdapter(sqlComm);

                    da.Fill(ds);
                }

解决方案

Try below
Resolving could not open a connection to SQL Server errors[^]
SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: )[^]


the network connection could not found in your connection...


Initial Catalog ="in your database connection name like db name "


string connString = string.Format("data source={0}; initial catalog={1}; Integrated Security ={2}; Connection Timeout={3}",





it may help you..


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

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