0
votes

i make a app in c# with a sql db, when i save data in the app, shows the error "Format of the initialization string does not conform to specification starting at index 73" in"system.argumentException"

i use windows autentication and this code for the conection:

   public static SqlConnection ObtenerConexion() 
   {
       SqlConnection Conn = new SqlConnection("Data source=VICTOR-PC; Initial Catalog=KAZIIM;  Integrated Security=True;");
       Conn.Open();


       return Conn;

   }
}

and the code fot the save data buttom is:

 private void btnGuardar_Click(object sender, EventArgs e)
    {
        Cliente Cliente = new Cliente();
        Cliente.ID_C = int.Parse(txtID.Text);
        Cliente.NOMBRES = txtNombres.Text;
        Cliente.CONTACTO = txtCorreo.Text;
        Cliente.CALLE = txtCalle.Text;
        Cliente.NUMERO = int.Parse(txtNumero.Text);
        Cliente.COLONIA = txtColonia.Text;
        Cliente.FECHA_ALTA = txtFecha.Text;

        int resultado = ClienteDAL.Agregar(Cliente);

        if (resultado > 0)
        {
            MessageBox.Show("Datos guardados con exito", "Datos Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            MessageBox.Show("No se grabaron los datos", "Error al guardar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

and the exception detail is:

System.ArgumentException was unhandled

HResult=-2147024809 Message=El formato de la cadena de inicialización no se ajusta a la especificación que comienza en el índice 73. Source=System.Data StackTrace: en System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) en System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) en System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) en System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) en System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) en System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) en System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) en System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) en System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential) en System.Data.SqlClient.SqlConnection..ctor(String connectionString) en app_topico.Kaziim.ObtenerConexion() en C:\Users\VICTOR\documents\visual studio 2010\Projects\app_topico\app_topico\Kaziim.cs:línea 14 en app_topico.ClienteDAL.Agregar(Cliente pCliente) en C:\Users\VICTOR\documents\visual studio 2010\Projects\app_topico\app_topico\ClienteDAL.cs:línea 14 en app_topico.Form1.btnGuardar_Click(Object sender, EventArgs e) en C:\Users\VICTOR\documents\visual studio 2010\Projects\app_topico\app_topico\Form1.cs:línea 35 en System.Windows.Forms.Control.OnClick(EventArgs e) en System.Windows.Forms.Button.OnClick(EventArgs e) en System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) en System.Windows.Forms.Control.WndProc(Message& m) en System.Windows.Forms.ButtonBase.WndProc(Message& m) en System.Windows.Forms.Button.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) en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) en System.Windows.Forms.Application.Run(Form mainForm) en app_topico.Program.Main() en c:\users\victor\documents\visual studio 2010\Projects\app_topico\app_topico\Program.cs:línea 18 en System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() en System.Threading.ThreadHelper.ThreadStart_Context(Object state) en System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) en System.Threading.ThreadHelper.ThreadStart() InnerException:

1
On which line you this exception exactly?Soner Gönül
hi! in this one: SqlConnection Conn = new SqlConnection("Data source=VICTOR-PC; Initial Catalog=KAZIIM; Integrated Security=True;");Victor Hernandez
Try removing excessive spaces and the last ";". The error says there is some error at he 73rd letter. Can there be some letter that does not show correctly? Paste your code line into notepad and then back into your code to get rid of "hidden" letters. Even better. Write that line again without any copy/paste.Wolf5
thanks for the support! @Soner GonulVictor Hernandez

1 Answers

0
votes

There seems to be an UTF-8 byte-order-mark at the very end of your connection string, between the ; and the " characters, exactly at the character position that the error says. It is invisible, but you can see it if you copy it to a new text file and save it with UTF-8 encoding and examine the file in a hex editor. Just delete the last few characters and type it again.

"Data source=VICTOR-PC; Initial Catalog=KAZIIM; Integrated Security=True;<some invisible stuff is here>"