KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've noticed that my code errors out on sqlWrite.ExecuteNonQuery(); after executing 200 Insert queries in couple of seconds. I always thought that using will make sure the resources are reused properly and there will be no need to do anything. This is the first time I get this error and I've been dealing with sql/c# for almost 3 years doing different things. using (SqlConnection varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails)) { using (var sqlWrite = new SqlCommand(preparedCommand, varConnection)) { sqlWrite.Parameters.AddWithValue("@var_agr_fname", var_agr_fname == "" ? (object) DBNull.Value : var_agr_fname); sqlWrite.ExecuteNonQuery(); } } public static SqlConnection sqlConnectOneTime(string varSqlConnectionDetails) { var sqlConnection = new SqlConnection(varSqlConnectionDetails); try { sqlConnection.Open(); } catch { DialogResult result = MessageBox.Show(new Form {TopMost = true}, "Błąd połączenia z bazą danych. Czy chcesz spróbować nawiązac połączenie ponownie?", "Błąd połączenia (000001)", MessageBoxButtons.YesNo, MessageBoxIcon.Stop); if (result == DialogResult.No) { if (Application.MessageLoop) { Application.Exit(); // Use this since we are a WinForms app } else { Environment.Exit(1); // Use this since we are a console app } } else { sqlConnection = sqlConnectOneTime(varSqlConnectionDetails); } } return sqlConnection; } Error message: A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, e
Tags (comma-separated)
Save Edits
Cancel