1

I am new at asp.net. I was trying database connection. But I am getting this error. Please advice me. enter image description here

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           string cs = "Data Source=.;Initial Catalog=test;Integrated Security=SSPI";
           SqlConnection con = new SqlConnection(cs);
           SqlCommand comma = new SqlCommand("select * from try", con);
           con.Open();
           GridView1.DataSource = comma.ExecuteReader();
           GridView1.DataBind();
           con.Close();

        }
    }
}
2
  • Your connection string is wrong - either that server (.) doesn't exist, or it's not started up yet, or something else is wrong with it Commented Jun 28, 2016 at 10:28
  • @marc_s you are right. Commented Jun 28, 2016 at 11:14

1 Answer 1

1

The issue is with the connection string you are using.

Data Source=.;Initial Catalog=test;Integrated Security=SSPI

Check the SQL Server instance name running on your local.

Data Source=**.\YourInstanceName**;Initial Catalog=test;Integrated Security=SSPI

You can test your connection string validity by trying to add a connection in Server Explorer (Tools -> Connect to Server - VS2015).

Good luck

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.