Home Asp.net Get Connection String to Connect SQL Database in Asp.net

Get Connection String to Connect SQL Database in Asp.net

6
0

Now here in this tutorial, I’ll explain the definition of SQL and how to get connection string to connect sql server database in Asp.net.

In my previous tutorials, I’d explained about sql injection with example, insert update and delete on asp.net gridview and other more cracking tutorials on GridView, Asp.net, SQL Server here.

 

What is sql?

The SQL stands for Structured Query Language, which is the set of instructions that used to communicate with a relational database.

SQL uses query statements that are used to perform data manipulation tasks such as insert, update, delete data from database tables, OR also we can retrieve data from a database tables. Some common relational database management systems that use SQL are Microsoft SQL Server, Oracle, Microsoft Access etc.

SQL has three major components:

    • 1. DML: The DML stands for Data Manipulation Language, which is used to manipulate with data of the database tables. Examples of commonly used DML commands are: INSERT (to insert data in database tables), UPDATE (to update existing data in database tables), DELETE (to delete existing data from database tables), SELECT (to retrieve existing data from database tables).

 

    • 2. DCL: The DCL stands for Data Control Language, which is used to manage user access to databases. There are mainly two commands are used: GRANT (to add database permissions for a user) and the REVOKE (to take away existing permissions). These two commands form the core of the relational database security model.

 

  • 3. DDL: The DDL stands for Data Definition Language, which is used to modify the actual structure of a database tables. Examples of commonly used DDL commands are: CREATE (to create new database tables, functions or store procedures), DROP (to modify existing structure of database tables, functions or store procedures), ALTER (to drop or delete existing database tables, functions or store procedures).

How to Get Connection String to Connect with Asp.net Application?

In SQL server, there are two ways for authentication available to access database. One is SQL Server Authentication, and another form of authentication is Windows Authentication.

If you are using Windows Authentication, then you can use the following connection string:

//For C#
string con = @”Data Source=server;Integrated Security=true;Initial Catalog=dbname”;//For Vb.net
Private con As String = “Data Source=server;Integrated Security=true;Initial Catalog=dbname”

OR

If you are using Server Authentication, then you can use the following connection string:

//For C#
string con = @”Data Source=server;User ID=user;Password=pwd;Initial Catalog=dbname”;//For Vb.net
Private con As String = “Data Source=server;User ID=user;Password=pwd;Initial Catalog=dbname”

Note: You need to replace server with your sql server name, user with your sql server authentication user id, pwd with your sql server authentication password and dbname with your sql database name that you want to connect with asp.net website.

You can also define your connection string in web.config under connectionStrings section or appSettings section this way. It’s totally depends on you how you want to use in your web application.

Example: Bind GridView with SQL Database and Show Data

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!