I using function ExecuteNonQuery() for insert and update and delete using c# .
This function using to make insert and update more thousand of records may be 10000 records so that computer hangs
to solve this problem i need to modify function
below to allow multi threads
so that i need to modify function to allow multi threads
How i do that in code
- public static int ExecuteNonQuery(string sql, DbParameter[] dbprmParameters = null)
- {
- return ExecuteNonQuery(sql, null, dbprmParameters);
- }
- public static int ExecuteNonQuery(string sql, IDbConnection dbConnection, DbParameter[] @params = null)
- {
- int RecordsCount = 0;
-
- lock (synObj)
- {
-
- if (cmd.CommandTimeout < 360)
- cmd.CommandTimeout = 360;
- if (sql == "") return 0;
-
- sql = AnalyizeBooleanFields(sql);
- cmd.CommandText = sql;
-
- cmd.Parameters.Clear();
-
- if (@params != null)
- {
- for (int i = 0; i < @params.Length; i++)
- {
- cmd.Parameters.Add(@params[i]);
- }
- }
- if (dbConnection == null)
- {
- if (WithTransaction)
- dbConnection = BeginTransaction();
- else
- dbConnection = InitializeConnection();
- }
- if (dbConnection.State != ConnectionState.Open) dbConnection.Open();
- if (WithTransaction) cmd.Transaction = _transaction;
- cmd.Connection = dbConnection;
- RecordsCount = cmd.ExecuteNonQuery();
- if (!WithTransaction) dbConnection.Close();
- }
- return RecordsCount;
- }
- public static string AnalyizeBooleanFields(string sql)
- {
- switch (DataAccess.Provider)
- {
- case Providers.Access2003:
- case Providers.Access2007:
- sql = sql.Replace("{{1}}", "True");
- sql = sql.Replace("{{0}}", "False");
- break;
- case Providers.SQLServer:
- case Providers.MySQL:
- case Providers.Oracle:
- default:
- sql = sql.Replace("{{1}}", "1");
- sql = sql.Replace("{{0}}", "0");
- break;
- }
- return sql;
- }
-
- }
How to edit function above to allow multi threads ?
I work in visual studio 2010 windows form application with sql server 2012 .