开发者

sql and pooled connection error

开发者 https://www.devze.com 2022-12-27 18:18 出处:网络
Kindly look at the following code as this sample code gives an error when i hosted it on Hostexcellence , but locally it runs perfect, and 开发者_开发知识库the error is as the following:

Kindly look at the following code as this sample code gives an error when i hosted it on Hostexcellence , but locally it runs perfect, and 开发者_开发知识库the error is as the following:

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached

SqlDataSource1.SelectCommand = "Select Top (3) * from News Order by NewsID Desc";
SqlDataSource1.DataSourceMode = SqlDataSourceMode.DataReader;
SqlDataReader r_News = (SqlDataReader)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
DataGrid_News.DataSource = r_News;
r_News.Close();
DataGrid_News.DataBind();

So What's wrong with that code ??


See this: http://msdn.microsoft.com/en-us/library/s4yys16a(VS.71).aspx

Public Sub ConnectToSql()
    Dim conn As New SqlClient.SqlConnection
    ' TODO: Modify the connection string and include any
    ' additional required properties for your database.
    conn.ConnectionString = & _
    "integrated security=SSPI;data source=SQL Server Name;" & _
    "persist security info=False;initial catalog=northwind"
    Try
        conn.Open()
        ' Insert code to process data.
    Catch ex As Exception
        MessageBox.Show("Failed to connect to data source")
    Finally
        conn.Close()
    End Try

End Sub

You should always include a finally clause to ensure that your connection is closed otherwise the connection will not be released (in case an exception occurs) and you will not have any more connections available.

0

精彩评论

暂无评论...
验证码 换一张
取 消