To put everyone in context: we have a deployed Windows Forms App, coded in C#, and querying data from/to a SQL Server 14 DB. Everything works fine, till the day we needed to push the app outside the main subnetwork 192.168.0.X, to 192.168.1.X.
Here with my partner, we believed that doing a little rework in the connection string could solve the first problem we had ahead (no connection to the DB; no login, no simple queries, no nothing), along this one, that doesn't allow us to write any data into the DB, using Stored Procedures or not. We already thinked that this could be one of the sources of this problem, but it wasn't, because we can do some SELECT queries without any drama. This, on the affected PC, of course.
Previously, it was:
user id=myUser; password=myPass; server=myIP; Trusted_Connection=no; database=myDBName; connection timeout=30;
Now, it is:
Data Source=myServerName; Initial Catalog=myDatabaseName; User ID=myUsername;Password=myPassword; Server=IP, Port (if necessary);
Some Screenshots of the Exceptions, printed in MessageBox'es:
1st (and 3rd) Exception: Possible Truncated Data (this repeats itself again after the 2nd one)
2nd Exception: Couldn't Open a Connection
We've already checked the TCP/IP, port configs from SSMS, physical firewall port forwarding, more variations on the conn. string, different IPv4 configs, and nothing seems to work (even with a new super user, with all DB and Server Privilegies). So here we are, so close, and so far from solving this thing.
2nd day Edit: Doing double checks in the affected code (where the Exceptions occur), even with the suggestions that @iakobski made, it's still the same. Same exceptions, in the same place. The only difference is the speed of the app to throw them, because it can close the pending transaction faster, and the exceptions are handled, thanks to the 'finally' clause.
Also, as I noticed while doing a deeper debugging, INSERT's or UPDATE's by themselves aren't the problem, but the Stored Procedures ones. Because it failed to Update/Select data in SP modules that uses the SQLSERVERPROCEDURE.SQLSERVER.Exec form, but not while inserting a Log Entry (which I believe is the classic way to execute SQL Commands):
SqlCommand cmd = new SqlCommand();
con.ConnectionString = CadenaConexion;
cmd.Connection = con;
cmd.CommandText = "INSERT INTO LOG(LOG_ID_USUARIO,LOG_FECHA,LOG_PROCESO,LOG_CANTIDAD,LOG_PEDIDO,LOG_ITEM)" +
"VALUES(@log_id_usuario, @log_fecha, @log_proceso, @log_cantidad, @log_pedido, @log_item)";
try
{
cmd.Parameters.Add("@log_id_usuario", SqlDbType.Int).Value = Log_id_usuario;
cmd.Parameters.Add("@log_fecha", SqlDbType.DateTime).Value = Log_fecha;
cmd.Parameters.Add("@log_proceso", SqlDbType.Text).Value = Log_proceso;
cmd.Parameters.Add("@log_cantidad", SqlDbType.Int).Value = Log_cantidad;
cmd.Parameters.Add("@log_pedido", SqlDbType.Int).Value = Log_pedido;
cmd.Parameters.Add("@log_item", SqlDbType.Int).Value = Log_item;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
return true;
}
catch (Exception ex)
{
exSrc = "log";
exMsg = ex.Message;
exNota = "ERR_LogUsu01: No se ha podido Insertar el Registro a la Tabla Log";
exStTr = ex.StackTrace;
registrarEnLogErr();
MessageBox.Show(ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
finally { con.Close(); }
So, if yesterday I was pretty sure that this little file called SQLSERVERPROCEDURE.dll that has direct relations with the Stored Procedures that are processed by it has a lot to do here, I'm sure-r now. Somehow, it may be using the old Connection String, but I don't know how I can change it, because every call that's done to this file, refers to the Conn. String as "DBSQL" (tried to change it when calling, putting the SharedData.Instance().StringConexion, and also a 'cn' variable [with ToString()], with no luck. Said that the Conn. String is not defined). Take a look at the definition in a SP with .dll calling, and the .dll file itself:
Update Module:
SqlConnection cn = new SqlConnection(SharedData.Instance().StringConexion);
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param.Add("@nta_venta", nta_venta);
param.Add("@item", item);
param.Add("@cantidad", cantidad);
cn.Open();
SQLSERVERPROCEDURE.SQLSERVER.Exec("DBSQL", SP, param);
cn.Close();
}
catch (Exception ex)
{
exSrc = this.Name;
exMsg = ex.Message;
exNota = "ERR_Corte02: Pedido: " + nta_venta + "-" + item + " con Falta de Parámetros válidos en Actualiza";
exStTr = ex.StackTrace;
registrarEnLogErr();
MessageBox.Show(ex.Message);
}
finally { cn.Close(); }
DLL File: Title on VS: SQLSERVER (from metadata)
#region Ensamblado SQLSERVERPROCEDURE, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null
// C:\Users\User\source\repos\MY-APP\packages\EXECSQLSERVERPROCEDURE.2.0.0\lib\net40\SQLSERVERPROCEDURE.dll
#endregion
using System.Collections.Generic;
using System.Data;
namespace SQLSERVERPROCEDURE
{
public static class SQLSERVER
{
public static DataTable Exec(string NombreConexion, string Procedimiento, Dictionary<string, object> VariableYValores, DataTable dt = null);
public static DataSet Exec(string NombreConexion, string Procedimiento, Dictionary<string, object> VariableYValores, DataSet ds = null);
public static void Exec(string NombreConexion, string Procedimiento, Dictionary<string, object> VariableYValores);
}
}
1st StackTrace (not valid anymore because it's resolved with re-done Open and Close statements):
Excepción producida: 'System.Data.SqlClient.SqlException' en System.Data.dll
El subproceso 0x3f5c terminó con código 0 (0x0).
Excepción producida: 'System.Data.SqlClient.SqlException' en SQLSERVERPROCEDURE.dll
Excepción producida: 'System.InvalidOperationException' en System.Data.dll
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Transactions.resources\v4.0_4.0.0.0_es_b77a5c561934e089\System.Transactions.resources.dll' cargado. El módulo se compiló sin símbolos.
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Excepción no controlada</Description><AppDomain>myApp.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>No está autorizado a cambiar la propiedad 'ConnectionString'. El estado actual de la conexión es abierta.</Message><StackTrace> en System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
en System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
en MY_APP.Class.log_errores.INSERT_log_err() en C:\Users\User\Source\Repos\MY-APP\MY APP\Class\log_errores.cs:línea 34
en MY_APP.PrcsCorte.registrarEnLogErr() en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 378
en MY_APP.PrcsCorte.cargarPedido(Int32 nv, Int32 it) en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 267
en MY_APP.PrcsCorte.PrcsCorte_Activated(Object sender, EventArgs e) en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 39
en System.Windows.Forms.Form.OnActivated(EventArgs e)
en System.Windows.Forms.Form.set_Active(Boolean value)
en System.Windows.Forms.Form.WmActivate(Message&amp; m)
en System.Windows.Forms.Form.WndProc(Message&amp; m)
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</StackTrace><ExceptionString>System.InvalidOperationException: No está autorizado a cambiar la propiedad 'ConnectionString'. El estado actual de la conexión es abierta.
en System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
en System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
en MY_APP.Class.log_errores.INSERT_log_err() en C:\Users\User\Source\Repos\MY-APP\MY APP\Class\log_errores.cs:línea 34
en MY_APP.PrcsCorte.registrarEnLogErr() en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 378
en MY_APP.PrcsCorte.cargarPedido(Int32 nv, Int32 it) en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 267
en MY_APP.PrcsCorte.PrcsCorte_Activated(Object sender, EventArgs e) en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 39
en System.Windows.Forms.Form.OnActivated(EventArgs e)
en System.Windows.Forms.Form.set_Active(Boolean value)
en System.Windows.Forms.Form.WmActivate(Message&amp; m)
en System.Windows.Forms.Form.WndProc(Message&amp; m)
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</ExceptionString></Exception></TraceRecord>
Excepción no controlada del tipo 'System.InvalidOperationException' en System.Data.dll
No está autorizado a cambiar la propiedad 'ConnectionString'. El estado actual de la conexión es abierta.
El subproceso 0x2e54 terminó con código 0 (0x0).
El subproceso 0x42cc terminó con código 0 (0x0).
El subproceso 0x3d84 terminó con código 0 (0x0).
Excepción no controlada: System.InvalidOperationException: No está autorizado a cambiar la propiedad 'ConnectionString'. El estado actual de la conexión es abierta.
en System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
en System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
en MY_APP.Class.log_errores.INSERT_log_err() en C:\Users\User\Source\Repos\MY-APP\MY APP\Class\log_errores.cs:línea 34
en MY_APP.PrcsCorte.registrarEnLogErr() en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 378
en MY_APP.PrcsCorte.cargarPedido(Int32 nv, Int32 it) en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 267
en MY_APP.PrcsCorte.PrcsCorte_Activated(Object sender, EventArgs e) en C:\Users\User\Source\Repos\MY-APP\MY APP\PrcsCorte.cs:línea 39
en System.Windows.Forms.Form.OnActivated(EventArgs e)
en System.Windows.Forms.Form.set_Active(Boolean value)
en System.Windows.Forms.Form.WmActivate(Message& m)
en System.Windows.Forms.Form.WndProc(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
El programa '[17180] myApp.exe' terminó con código 0 (0x0).
2nd StackTrace:
'myApp.exe' (CLR v4.0.30319: DefaultDomain): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: DefaultDomain): 'C:\Users\User\Source\Repos\MY-APP\MY APP\bin\Debug\myApp.exe' cargado. Símbolos cargados.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.resources\v4.0_4.0.0.0_es_b77a5c561934e089\System.Data.resources.dll' cargado. El módulo se compiló sin símbolos.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms.resources\v4.0_4.0.0.0_es_b77a5c561934e089\System.Windows.Forms.resources.dll' cargado. El módulo se compiló sin símbolos.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_es_b77a5c561934e089\mscorlib.resources.dll' cargado. El módulo se compiló sin símbolos.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\Users\User\Source\Repos\MY-APP\MY APP\bin\Debug\SQLSERVERPROCEDURE.dll' cargado. No se encuentra el archivo PDB o no se puede abrir.
'myApp.exe' (CLR v4.0.30319: myApp.exe): 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.dll' cargado. Se omitió la carga de símbolos. El módulo está optimizado y la opción del depurador 'Sólo mi código' está habilitada.
Excepción producida: 'System.Data.SqlClient.SqlException' en System.Data.dll
Excepción producida: 'System.Data.SqlClient.SqlException' en System.Data.dll
El subproceso 0x1184 terminó con código 0 (0x0).
El subproceso 0xfe0 terminó con código 0 (0x0).
El subproceso 0xc70 terminó con código 0 (0x0).
El subproceso 0x4b64 terminó con código 0 (0x0).
El subproceso 0x5e04 terminó con código 0 (0x0).
El subproceso 0x3ef4 terminó con código 0 (0x0).
El subproceso 0x3b58 terminó con código 0 (0x0).
El subproceso 0x480c terminó con código 0 (0x0).
Excepción producida: 'System.Data.SqlClient.SqlException' en SQLSERVERPROCEDURE.dll
El subproceso 0x48f0 terminó con código 0 (0x0).
El subproceso 0x4238 terminó con código 0 (0x0).
Excepción producida: 'System.Data.SqlClient.SqlException' en System.Data.dll
El subproceso 0x5ddc terminó con código 0 (0x0).
El subproceso 0x5184 terminó con código 0 (0x0).
El subproceso 0x3074 terminó con código 0 (0x0).
El subproceso 0x3bdc terminó con código 0 (0x0).
El subproceso 0x55f4 terminó con código 0 (0x0).
El subproceso 0x44b4 terminó con código 0 (0x0).
El programa '[18484] myApp.exe' terminó con código 0 (0x0).
SSMS Screenshots: