Previous Code Entry
Left Arrow
SQL Server Management Studio - Change Table Owner
Current Code Entry
Next Code Entry
SQL Server Core Installation Script
Right Arrow
How to use SQL Server Database Connection string
Article Entry Date: August 18,2022 @ 11:15:19 / Last Updated On: October 13,2022 @ 12:29:54
In all lessons with a SQL Server database connection, you will have a Connection string supplied to you with the database and table SQL scripts so that you can follow along with the code provided in the lesson.

(The below names will change depending on the lesson you are doing, but all will be similar)
SQL Server.
Step 1:
Create a new Database named, [Test]
Right-click on [Databases]
Choose [New Database]
When Dialog opens.
Database Name: Test
Choose [OK]

Step 2:
Create a new SQL Server Database user named , [testuser]
Right-click on [Security]
Choose [New] | [Login]
Login name: testuser
Select [SQL Server authentication]
password: testuser
confirm password: testuser
Under [Select a page]
Choose [Server Roles]
Add a check to [sysadmin]
Next
Choose [User Mapping]
From the [User mapped to this login]
Choose the [Test] database.
Click [OK]

Step 3:
Right-click on the new database [Test]
Choose [New Query]
Copy and Paste the code from the [SQL] tab into the Query window, and click on [Execute]
You should now have a table called Tags with nine records.

Step 4:
Create our connection string to our newly created database.
In a new file, copy and paste the code.
Classic ASP
Top of the [ASP] tab and save the file as ACN.asp
Top of the [ASP.NET] tab and save the file as database.config

The below items need changing to your system specs.
  1. [getServer] = this is the Computer (or) Server name.
  2. [getInstance] = This is the SQL Server instance name.
  3. [getID] = Username of the SQL User
  4. [getPW] = Password of the SQL User
  5. [getCat] = The name of the Database


Classic ASP (Copy and paste and save as ACN.asp)


VB and C# (Copy and paste and save as database.config, then refer to this file from Web.config)