SQL 超时错误

发布于 2024-11-16 06:46:33 字数 1172 浏览 0 评论 0原文

我一直在 SQL 程序上遇到超时问题,我已将其范围缩小到此函数,我可以传递参数和它的单词,但在本例中我发送了数百个。当它运行时,我遇到超时,可能有 6 次左右进入数据库,然后大约 2 分钟后发生超时。当本地运行时,一切正常,操作在几秒钟内完成。!!有什么想法吗? 。

我知道它获取所需的信息并进入列表,它可以连接并向 SQL 发送数据。我读过也许创建了太多连接之类的内容,但似乎没有什么可以解决它。您遇到过任何想法或简单的问题吗?还尝试根据以下内容禁用调试器等

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();
    }
}

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 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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

全部不再 2024-11-23 06:46:33

尝试传递您的开放连接。打开一个sql连接是非常昂贵的。

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();

}

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();

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文