programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Wednesday, November 5, 2014 database connection with sql server using c# sql server database connection using c#:

Sql server database connection in

In this post we describe how to create connection from sql data base in C# web page. Here we consider basically on page connection. In we have many choices to make sql connection here we use on page connectivity from data base.

You can connect your C# application to data in a SQL Server database using the .NET Framework Data Provider for SQL Server. The first step in a C# application is to create an instance of the Server object and to establish its connection to an instance of Microsoft SQL Server.

For Make sql connection  we use fallowing steps:

Step 1:
  • Open IED make a page for text the connection.
  • Go to Server Explorer and add new data base. database connection with sql server using c#

  • Type the server name then authorization type then database name and click ok button.

Step 2:
  • Go to connected database and right click on name.
  • Go to propriety window. database connection with sql server using c#

Step 3:
  • Copy the connection string from propriety window.
  • Use this connection string for make connection in page. database connection with sql server using c#

Code of C# page in of connection:

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

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
         string connetionString = null;
            SqlConnection cnn ;
       // past the connection string here……………………..
                     connetionString = @"Data Source=PARIJAT-PC\PARIJAT;Initial Catalog=my_testing;Integrated Security=True";
            cnn = new SqlConnection(connetionString);
                Label1.Text = "Connection Open ! ";
            catch (Exception ex)
                Label1.Text = " can not open connection ! ";
} .aspx page code for test connection:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <div align="center">
    Database connection check and login.

    <h3> click on button and check data base connect or not .</h3>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
                Text="Check conn" />
            <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>
</html> database connection with sql server using c#

Other Related post :

No comments:

Post a Comment