locked
Gridview RRS feed

  • Question

  • User-34350291 posted

    Hi Experts,

    I have develop a sample web application with gridview and sql server as db.

    But i have an error in
    con.open() -- Instance Failure

    web.config

    <connectionStrings>
    <add name ="vel" connectionString="server=MURUGAVEL-PC\\SQLEXPRESS; database=Northwind; Integrated Security=True" />
    </connectionStrings>

    Test.cs

    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    SqlDataReader dr;
    con.ConnectionString = ConfigurationManager.ConnectionStrings["vel"].ConnectionString;
    con.Open();
    cmd.CommandText = "select * from Employees";
    cmd.CommandType = CommandType.Text;
    cmd.Connection = con;

    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    GridView1.DataSource = dr;
    GridView1.DataBind();

    con.Close();

    Plz help me out

    Thanks
    Murugavel S

    Sunday, January 27, 2013 10:30 AM

Answers

  • User433377059 posted

    There is a double slash \\ in your connection string declaration.

    Remove it, this should work.

    <connectionStrings>
    <add name ="vel" connectionString="server=MURUGAVEL-PC\SQLEXPRESS; database=Northwind; Integrated Security=True" />
    </connectionStrings>



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 27, 2013 11:06 AM