In the code below i see this error when i try to connect to connection string this error appears

Format of the initialization string does not conform to specification starting at index 0.

How can i fix it?
In the code below i see this error when i try to connect to connection string thiss error appears

Format of the initialization string does not conform to specification starting at index 0.

How can i fix it?

    namespace InsertUserApp
    {
        public partial class Home : Form
        {
            class ComboItemExample
            {
                public string DisplayString { get; set; }
                public string ConnectionString { get; set; }

                public override string ToString() { return DisplayString; }
            }
            private string connstring = "<default connection>";

            public Home()
            { 
                InitializeComponent();

                var srv1 = new ComboItemExample { DisplayString = "Srv1", ConnectionString = "Data Source=tcp:10.0.0.110;Initial Catalog=Database1;User ID=user;Password=pass;" };
                cmbSrv.Items.Add(srv1);

                var srv2 = new ComboItemExample { DisplayString = "Srv2", ConnectionString = "Data Source=tcp:10.1.0.11;Initial Catalog=Database2;User ID=user;Password=pass;" };
                cmbSrv.Items.Add(srv2);

                var srv3 = new ComboItemExample { DisplayString = "Srv3", ConnectionString = "Data Source=tcp:10.1.0.15;Initial Catalog=Database3;User ID=user;Password=pass" };
                cmbSrv.Items.Add(srv3);

            }


                private void txtID_TextChanged(object sender, EventArgs e)
        { 
                using (SqlConnection connection = new SqlConnection(connstring))
                {
                    /*if (String.IsNullOrEmpty(txtID.Text))
                    {
                        MessageBox.Show("Plotesoni fushat UnID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    }
                    else
                    {*/
                    SqlCommand command1 =
                    new SqlCommand("select * from Table1 WHERE Tag = 'User' and UnId = '" + txtID.Text + "'", connection);
                    SqlCommand command2 =
                    new SqlCommand("select * from Table1 WHERE Tag = 'Pass' and UnId = '" + txtID.Text + "'", connection);
                    SqlCommand command3 =
                    new SqlCommand("select * from Table1 WHERE Tag = 'Shifra1' and UnId = '" + txtID.Text + "'", connection);
                    SqlCommand command4 =
                    SqlCommand command5 =
                    new SqlCommand("select * from Table2 WHERE UnId = '" + txtID.Text + "'", connection);
                    connection.Open();

                    SqlDataReader read1 = command1.ExecuteReader();


                    while (read1.Read())
                    {
                        txtID.Text = (read1["UnId"].ToString());
                        txtUser.Text = (read1["Value"].ToString());

                    }
                    read1.Close();
                    SqlDataReader read2 = command2.ExecuteReader();
                    while (read2.Read())
                    {
                        txtPass.Text = (read2["Value"].ToString());
                    }
                    read2.Close();
                    SqlDataReader read3 = command3.ExecuteReader();
                    while (read3.Read())
                    {
                        txtOrg.Text = (read3["Value"].ToString());
                    }
                    read3.Close();
                    SqlDataReader read5 = command5.ExecuteReader();
                    while (read5.Read())
                    {
                        txtgrp.Text = (read5["shifra1"].ToString());
                    }
                    read5.Close();
                }
            }


            }
        }
    }

In looking at your code, I don't see anyplace that the correct connection string is assigned to connstring. Instead of using a separate global variable, you might be better off using the SelectedText of cmbSrv.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.