开发者

SQl error with timeout

I have been having trouble with timeout on SQL program , I have narrowed it down to this function , i can pass parameters and it words , but in this instance I send a couple hundered . When it runs I get a timeout and maybe 6 or so get through into the database and then timeout occurs in about 2minutes. when run locally everything works fine and operations complete in a few seconds.!! any ideas? .

I know its getting the information it needs and gettting into the list and it can connect and send data to SQL. I have read maybe creating too开发者_Go百科 many connections and the like but nothing seems to fix it. Any ideas or simple problems you have come accross?. also tried disabling debuggers etc as per

public void ConnectToSQl(String word, int count, String HashTag = " ")
{
    checkExcludeList();
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Data Source = dev\\SQLEXPRESS ;" +
                            "Initial Catalog=sml;" + 
                            "User id=**** ;" + 
                            "Password =******;" + 
                            "Trusted_Connection=No";
    try {
        conn.Open();
        SqlCommand Command = new SqlCommand("INSERT INTO word_list (word , count)" +
                                            "VALUES (@word , @count)", conn);
        //add parameters for insert
        Command.Parameters.AddWithValue("@word", word);
        Command.Parameters.AddWithValue("@count", count);
        Command.ExecuteNonQuery();
    } catch (Exception e) {
        Box.Text = "SQL error" + e;
    } finally {
       conn.Close();
    }
}


Try passing in your open connection. Opening a sql connection is very expensive.

public void ConnectToSQl(SqlConnection conn, String word, int count, String HashTag = " ")
{   
    if (conn.State != ConnectionState.Open)
        throw new SqlExecutionException("Sqlconnection is not open");

    checkExcludeList();

    SqlCommand Command = new SqlCommand(
        "INSERT INTO word_list (word , count)" +
        "VALUES (@word , @count)", conn);

    //add parameters for insert
    Command.Parameters.AddWithValue("@word", word);
    Command.Parameters.AddWithValue("@count", count);

    Command.ExecuteNonQuery();

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜