关于C#的odbcConnection连接超时问题
我用C#做了一个Sqlserver的自动备份迁移的功能,但用odbc连接数据库后,备份大的数据库时,时间一长就出错。提示:
System.Data.Odbc.OdbcException: ERROR [HYT00] [Microsoft][ODBC SQL Server Driver]超时已过期
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at AutoSQLbackup.Form1.backupDatebase(String backType) in D:\AutoSQLbackup\AutoSQLbackup\Form1.cs:line 274
我已经设了ODBC的连接超时了,但不起效,以下是连接的设置
C# code
OdbcConnection dbConn = null;
string connectString = "Driver={SQL Server};Server="
+ serverName
+ ";UID=" + userName
+ ";PWD=" + pword
+ ";Database=" + dbName + ";";
dbConn = new OdbcConnection(connectString);
dbConn.ConnectionTimeout = 60 * 60 * 2;
dbConn.Open();
return dbConn;
请大侠指教
------解决方案--------------------
在OdbcCommand.CommandTimeout设置下看看呢
------解决方案--------------------