Creating c# SQL Connection String

1. Open new text file then named it with .udl extension file name.


2. Select icon, then open with notepad.

text like this will show..

[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=db_info;Data Source=JESSON\SQLEXPRESS

3. Open or double click the .udl icon window pop like this, then hit "Provider"




4. Select Microsoft OLE DB Provider for SQL Server the hit OK.

5. On "Connection Tab" Select Use Windows NT Integrated Security. see picture below.


6. On windows form Add this Declaration;
                              
                     using System.Data.OleDb;

7. On your form load Add the following;

                     private void Form1_Load(object sender, EventArgs e)
        {

            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=db_info;Data Source=JESSON\\SQLEXPRESS";
            con.Open();
        }

Enjoy!!!!




1 comment:

  1. hey, your guide looks simple n easy to understand (from layman point of view lah) :)

    ReplyDelete