Md. Shohan Hossain
Md. Shohan Hossain

Reputation: 118

System.Data.SqlClient.SqlException error at asp.net

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

        }
    }
}

Upvotes: 1

Views: 1247

Answers (1)

Roy Paruchuri
Roy Paruchuri

Reputation: 106

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

Upvotes: 1

Related Questions