Connection to SQL Server with ASP

Who I am
Joel Fulleda
Author and references

SQL Server it's a powerful one DBMS home relational Microsoft which works in a similar way to the already known Accesswhile offering far superior services, power and stability.

In this article we will see how to interface a script Aspen to a database SQL Server.

SQL Server is first and foremost an end-to-end data management and analysis solution for building, deploying and managing business applications. 

Connection to SQL Server with ASP

We create in Sql Server a database db_prova inside which we create the table user_tab. We create the fields id (Type: number - Identity: Yes), name (Type: char) and last name (Type: char). Let's open the table and insert some test data.

Let's create a Connection.asp and insert the following code

Nothing different than a connection and a query on a database Access: 'the only thing that changes, programmatically Aspen is the database connection string that has the following form:

Driver = {SQL Server}; Server = SOULTRICKS; Database = db_prova; Uid = sa; Pwd = sa;

Where Server & Hosting indicates the name of the server on which the database is located, where the server version of SQL Server is therefore installed; Database indicates the name of the database to connect to; Uid e pwd indicate the SQL Server login credentials.

However, you can specify username and password in the connection string.

In ASp it is indicated to recommend the file global.asa, so as not to repeat the entire database connection string in the pages every time, but to use an application variable and then refer to this variable when the connection is opened.

For example:

Fillet global.asa:

Sub Application_OnStart
Application(“ConnessioneDB”) = “Driver={SQL Server};Server=SOULTRICKS;Database=db_prova;Uid=sa;Pwd=sa;”
End Sub

ASP page example for data access:

Connection to Databse

Data 1:

add a comment of Connection to SQL Server with ASP
Comment sent successfully! We will review it in the next few hours.