0
votes

I inserted path of connection string to database(A). The path use for connect database(B). When i select that path from database(A) and try to connect database(B). This is alert message show

Keyword not supported: '@"data source'.'

This is connectstring in database(A) :

@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\it_staff\source\repos\MonitorProduction_Client\MonitorProduction_Client\App_Data\monitorclientdb.mdf;Integrated Security=True"

connect_db.conn.Close();
connect_db.conn.Open();
SqlCommand cmd_select_connect_string = new SqlCommand("select board_connect_string from[board] where board_id='" + board_id_[0] + "'", connect_db.conn);
        if (cmd_select_connect_string.ExecuteNonQuery() != 0)
              {
                    SqlDataReader rd = cmd_select_connect_string.ExecuteReader();
                    while (rd.Read())
                    {
                        var board_connect_string = rd[0];
                        connect_db.connb=new SqlConnection(board_connect_string.ToString());  
                    }
                }
1
You need to share the code which throws the error.Chetan
Are you setting that connection string in web.config? Doing so may cause configuration parser error since you're adding newline in middle of connection string and usage of @ before opening double quotes which is not allowed.Tetsuya Yamamoto
But when i change board_connect_string.ToString() is (@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\it_staff\source\repos\MonitorProduction_Client\MonitorProduction_Client\App_Data\monitorclientdb.mdf;Integrated Security=True") it can connectedlew sitthisak
And why you're using both ExecuteNonQuery and ExecuteReader on a SELECT query? You can just use HasRows property after doing ExecuteReader, no need to use ExecuteNonQuery here. Also check if connection string contains incorrect newline or wrong providerName.Tetsuya Yamamoto
Just check that can query or not. But thank you to give Instructive me. But my problem still not fix it.lew sitthisak

1 Answers

0
votes

Just remove @ and both " from connect_string in database

Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\it_staff\source\repos\MonitorProduction_Client\MonitorProduction_Client\App_Data\monitorclientdb.mdf;Integrated Security=True