0

在我的应用程序中,Application_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_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();
        }
    }
4

1 回答 1

1

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

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

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

这可能会有所帮助......因为它将摆脱一些“解决”检查。

于 2013-05-28T18:54:18.660 回答