Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET首次访问数据库错误_Asp.net_Iis 7_Sql Server 2008 R2 - Fatal编程技术网

ASP.NET首次访问数据库错误

ASP.NET首次访问数据库错误,asp.net,iis-7,sql-server-2008-r2,Asp.net,Iis 7,Sql Server 2008 R2,在我的应用程序中的Application\u Start()中,我从数据库中加载一些静态数据以供进一步使用。但问题是,当服务器空闲一天时,则对Db的第一个请求不成功,并返回此错误: The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the followin

在我的应用程序中的
Application\u Start()
中,我从数据库中加载一些静态数据以供进一步使用。但问题是,当服务器空闲一天时,则对Db的第一个请求不成功,并返回此错误:

The client was unable to establish a connection because of an error during connection initialization process before login.
Possible causes include the following:
the client tried to connect to an unsupported version of SQL Server;
the server was too busy to accept new connections;
or there was a resource limitation (insufficient memory or maximum allowed connections) on the server.

(provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
然后刷新后,一切正常。有什么想法吗?为什么每天都调用
Application\u Start()
?我认为它只有在第一次请求应用程序时才被调用,然后才从IIS重新启动它

编辑:
我正在使用SQL server 2008R2 express
我认为我的代码中应该没有问题,但她的问题是:

    public static SqlConnection sqlCon()
    {
        return new SqlConnection(WebConfigurationManager.ConnectionStrings["Test"].ConnectionString);             
    }
public void fillFromDB()                                      
    {
        SqlConnection con = defVal.sqlCon();
        SqlCommand cmd_getK = new SqlCommand("usp_getAllKomponenty", con);
        cmd_getK.CommandType = CommandType.StoredProcedure;
        try
        {
            con.Open();
            SqlDataReader reader = cmd_getK.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    this.adKomp(reader[0].ToString(), new elisKomponent(reader[0].ToString(), reader[1].ToString(), new date(Convert.ToInt32(reader[2]))));
                }
                reader.Close();
            }
        }
        catch (SqlException e)
        {
            throw new ApplicationException("Chyba při čtení komponenty databáze"+e.Message);
        }
        finally
        {
            con.Close();
        }
    }

请尝试更多/最具体的连接字符串类型

IP地址,端口号。网络协议

Data Source=192.168.1.333,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;
User ID=myUsername;Password=myPassword;

这可能会有帮助……因为它将消除一些“解析”检查。

您使用的是哪个版本的sql server?用于收集此数据的代码在哪里?感觉您有一个
SqlConnection
的实例,您正在存储它(您不应该这样做),并在以后再次尝试利用它。始终创建新对象并正确处理
SqlConnection
对象。请查找“using”语句。你会想走那条路的…所以你得到了IDispose。处理被呼叫的情况。使用你的连接,然后处理它们…….不要试图超越它…让连接池为你处理巫毒…特别是在asp.net网站上。我尝试了Using语句并启用了池,但没有任何更改连接字符串看起来像这样,但这不应该是问题,这就像我第一次尝试访问服务器时服务器被卡住了一样,但事实并非如此。当我通过我的远程destkop登录到服务器时,我的应用程序正在尝试连接,我能够连接,但是应用程序仍然没有。当你输入服务器名时,它必须被解决。当您不输入端口号时,它必须计算出端口号。如果不指定网络协议,它将使用注册表中的默认协议。只是尝试更改连接字符串是一种廉价的尝试。我不是说你的连接字符串错了,我是说你可以尝试让它更具体。