2016-05-09 2 views
-4

В коде ниже я вижу эту ошибку, когда я пытаюсь подключиться к строке подключения thiss ошибка появляетсяSqlConnection 0 в C#

Формат строки инициализации не соответствует спецификации, начиная с индекса 0.

Как я могу это исправить? В коде ниже я вижу эту ошибку, когда я пытаюсь подключиться к цепи ошибок строка thiss появляется

Формат строки инициализации не соответствует спецификации, начиная с индекса 0.

Как я могу это исправить?

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(); 
      } 
     } 


     } 
    } 
} 
+0

Итак, это строка соединения, используемая при подключении? –

+0

Кроме того, я бы сменил ваш пароль в базе данных с тех пор, как вы разместили его здесь ... –

+0

{ using (SqlConnection connection = new SqlConnection (connstring)) } также имя пользователя и пароль являются просто образцом не реальным – aarriiaann

ответ

0

, как я рассмотрел через интернет я думаю, что проблема в этой строке кода

какие-либо предложения?

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); 
Смежные вопросы