I want to make a connection to MSSQL 2008 database, using Visual Studio 2010, ASP.NET C# web site
I wrote this connection string in web.config file:

    <add name="konekcija"
         connectionString="data source=.\SQLEXPRESS;Initial Catalog=Movies;Integrated Security=True;" providerName="System.Data.SqlClient" />

Now I need to call that connection on a code behind the page... something like:
SqlConnection conn = new SqlConnection.... can anyone help?

ow I need to call that connection on a code behind the page...

 protected void Page_Load(object sender, EventArgs e)
            if (!this.IsPostBack)

        private void BindEmployeesList()
            string connectionString = ConfigurationManager.ConnectionStrings["NorthwindConnString"].ConnectionString;
            string selectSQL = "SELECT [LastName], [FirstName], [Title], [City], [Email] FROM [Employees]";
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            adapter.Fill(ds, "Employees");

            gvEmployeesList.DataSource = ds;

Thanks Dhaker... I needed C#
I found out what to do... here is the code snippet:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
                SqlCommand cmd = new SqlCommand("SELECT * FROM someTable", conn);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.