Connecting C# Applications to SQL

Connecting C# Applications to SQL:
Creating Sql Connection:
There are different ways to create a Sql connection. Most commonly used are
·         Through UDL file
·         From C# Application 
Through UDL File:
·         Create a new text document file.
·         Open the file.
·         Name the file and save the file with .UDL extension.
·         A new UDL file will be created.
·         Right click the file and go to Properties.
·         A properties window will be displayed like this.
·         Go to the Provider tab.
·         Select Microsoft OLE DB Provider for SQL Server.
·         Now go to Connection tab.
·         Enter Server Name.
·         Select Windows Authentication if you are not a database user.
·         Select Sql Server Authentication if you are a database domain user.
·         Specify your User name and password which you use to connect to Sql Server.
·         Now select your Database.
·         Now click on Test Connection button.
·         If you have entered all information correctly a message box will appear”Test Connection Succeeded.”  
·         Now go to the UDL file and open it with notepad you will see a connection string in it which you will use in your application to connect to Sql server.
·         Now copy this connection string and use it in your application.
From C# Application:
·         Open a new WindowsFormApplication.
·         Go to the tab Tools.
·         Select Connect To Database.
·         A window will appear.
·         Choose your data source as Microsoft Sql Server.
·         Enter Server Name.
·         Select Windows Authentication if you are not a database user.
·         Select Sql Server Authentication if you are a database domain user.
·         Specify your User name and password which you use to connect to Sql Server.
·         Now select your Database.
·         Now click on Test Connection button.
·         If you have entered all information correctly a message box will appear “Test Connection Succeeded.”
·         Now in Server Explorer window you will see a connection.
·         Select that connection and go to properties window.
·         Here you will see a property Connection String and a string in front of that property this is your connection string that you will use in your application.




                       

Comments

Popular posts from this blog

Using Progress Bar In C#

Get elements by class name in javascript

Jquery serer side datatables in asp.net