ASP connection SQL2005 Database connection code _ database related

Source: Internet
Author: User
Description
A, the following character database name forum, database server name www-2443d34e558\sql2005 (or 127.0.0.1)
b, view SQL database server Name: Object Explorer-> database-> right click on its own built database-> properties-> permissions
C, PROVIDER=SQLNCLI also can, UID and "=" can not have a space between, if you exchange the user ID can have
Spaces, Initial catalog can be swapped with DATABASE,PWD can be swapped with Password,data source to swap with the server,
In VBScript, it is case-insensitive, so the UID equals UID equals uid ... , where provider, UID, PWD,
Initial Catalog, data source and other locations are free to put
(1), Windows Authentication connection SQL2005 string, using integrated Security=sspi method
Copy Code code as follows:

' The following is the establishment of the Connection object connection database
Dim Conn
Set conn=server.createobject ("ADODB. Connection ")
Sql= "Provider=sqloledb;data source=www-2443d34e558\sql2005; uid=; Pwd=;initial catalog=forum;integrated Security=sspi "
Conn. Open SQL
' The following is the decision whether to connect
If conn.state=2 Then
Response.Write ("Connecting")
ElseIf conn.state=1 Then
Response.Write ("Connection is already open")
Else
Response.Write ("Sorry, unable to open connection")
End If

(2) SQL Server user name authentication connection method, in which the SQL user name is SA, password ********
Copy Code code as follows:

' The following is the establishment of the Connection object connection database
Dim Conn
Set conn=server.createobject ("ADODB. Connection ")
Sql= "Provider=sqloledb;data source=www-2443d34e558\sql2005; Uid=sa; Pwd=********;initial Catalog=forum "
Conn. Open SQL
' The following is the decision whether to connect
If conn.state=2 Then
Response.Write ("Connecting")
ElseIf conn.state=1 Then
Response.Write ("Connection is already open")
Else
Response.Write ("Sorry, unable to open connection")
End If

(3), the above two methods can also be used in the following ways
Copy Code code as follows:

Dim Sqldatabasename,sqlpassword,sqlusername,sqllocalname,connstr,conn
Sqldatabasename = "forum" ' SQL database name
sqlusername = ' sa ' SQL database username
SQLPassword = ' ********** ' SQL database user password
Sqllocalname = "www-2443d34e558\sql2005" "SQL Host IP address (server name)
ConnStr =" Password = "&SqlPassword&"; User ID = "& sqlusername&"; Initial Catalog = "&SqlDatabaseName&"; Data Source = "& Sqllocalname &"; Provider = SQLOLEDB; "
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open connstr

If conn.state=2 Then
Response.Write (" Connecting ")
ElseIf conn.state =1 Then
Response.Write ("Connection is turned on")
Else
Response.Write ("Sorry, cannot open connection")
End If

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.