简体   繁体   中英

SqlClient.SqlException: The wait operation timed out

I'm currently trying to create a large amount of test data with numerous insert statements using code similar to below...

using (var connection = new SqlConnection(_connectionString))
{
    using (var command = new SqlCommand(query.ToString(), connection))
    {
        try
        {
            connection.Open();

            command.ExecuteNonQuery();

            return true;
        }
        catch (Exception e)
        {
            ......
        }
    }
}

My problem is that I keep getting an error

The wait operation timed out

and yet when I run the SQL statement that failed from within SQL Server Management Studio, it executes in less than 100ms. The error always seems to occur whilst inserting into the largest table which currently has 47,738,476 rows and is 1,970,696Kb in size.

I'm using:

Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 
Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

Any, help would be most appreciated.

Disclaimer: It may not be an answer but it solves the problem :)

Use Redgate Sql Data Generator

http://www.red-gate.com/products/sql-development/sql-data-generator/

It is not free but it is fully functional trial for some days and it will do the work for you what i want to achieve.

It had lot of option and generate real looking data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM