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