5个回答
展开全部
方法有很多种,我只是举例一种
在程序页面中引用就这个文件
<!-- #include file=conn.asp -->
conn.asp代码如下:
<%@ LANGUAGE = VBScript CodePage = 936%>
<%
option explicit
Response.Buffer = True
Response.Expires= 0
On Error Resume Next
Dim SqlNowString
Dim Conn,Db
Startime=timer()
'可修改设置一:========================定义数据库类别,1为SQL数据库,0为Access数据库=============================
Const IsSqlDataBase = 0
'================================================================================================================
If IsSqlDataBase = 1 Then
'必修改设置二:========================SQL数据库设置=============================================================
'sql数据库连接参数:
Const SqlUsername = "" '用户名(SqlUsername)、
Const SqlPassword = "" '用户密码(SqlPassword)
Const SqlDatabaseName = "" '数据库名(SqlDatabaseName)
Const SqlLocalName = "(local)" '(本地用local,外地用IP)
'================================================================================================================
SqlNowString = "getdate()"
Else
'必修改设置三:========================Access数据库设置==========================================================
'用户第一次使用请修改本处数据库地址并相应目录中数据库名称
Db = "/Database/Database.mdb"
'================================================================================================================
SqlNowString = "Now()"
End If
Dim ConnStr
If IsSqlDataBase = 1 Then
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
Else
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
End If
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"'注释
Response.End
End If
%>
在程序页面中引用就这个文件
<!-- #include file=conn.asp -->
conn.asp代码如下:
<%@ LANGUAGE = VBScript CodePage = 936%>
<%
option explicit
Response.Buffer = True
Response.Expires= 0
On Error Resume Next
Dim SqlNowString
Dim Conn,Db
Startime=timer()
'可修改设置一:========================定义数据库类别,1为SQL数据库,0为Access数据库=============================
Const IsSqlDataBase = 0
'================================================================================================================
If IsSqlDataBase = 1 Then
'必修改设置二:========================SQL数据库设置=============================================================
'sql数据库连接参数:
Const SqlUsername = "" '用户名(SqlUsername)、
Const SqlPassword = "" '用户密码(SqlPassword)
Const SqlDatabaseName = "" '数据库名(SqlDatabaseName)
Const SqlLocalName = "(local)" '(本地用local,外地用IP)
'================================================================================================================
SqlNowString = "getdate()"
Else
'必修改设置三:========================Access数据库设置==========================================================
'用户第一次使用请修改本处数据库地址并相应目录中数据库名称
Db = "/Database/Database.mdb"
'================================================================================================================
SqlNowString = "Now()"
End If
Dim ConnStr
If IsSqlDataBase = 1 Then
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
Else
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
End If
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"'注释
Response.End
End If
%>
展开全部
<%
Set Cnn = Server.CreateObject("ADODB.Connection")
StrCnn = "Driver={SQL Server};Server=SQL服务器地址名(如果是本地就填127.0.0.1);UID=sa;PWD=123;Database=数据库名"
Cnn.Open StrCnn
%>
具体用户名密码数据库名按自己的实际情况改动
或者用DW
Set Cnn = Server.CreateObject("ADODB.Connection")
StrCnn = "Driver={SQL Server};Server=SQL服务器地址名(如果是本地就填127.0.0.1);UID=sa;PWD=123;Database=数据库名"
Cnn.Open StrCnn
%>
具体用户名密码数据库名按自己的实际情况改动
或者用DW
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先创建一个连接数据库的ASP文件,一般以conn.asp 或是 dbase.asp等。
conn.asp 的源代码 和一楼的差不多
然后在其它的程序中引用就行了
<!-- #include file=conn.asp -->
conn.asp 的源代码 和一楼的差不多
然后在其它的程序中引用就行了
<!-- #include file=conn.asp -->
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2008-08-07
展开全部
有如下两种方法:
SQL server连接方法:
set adocon=server.createobject("adodb.recordset")
adocon.Open"Driver={SQL Server};Server=(Local);UID=***;PWD=***;"& _
"database=数据库名;"
SQL server OLE DB连接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"provider=SQLOLEDB.1;Data Source=RITANT4;"& _
"user ID=***;Password=***;"& _
"inital Catalog=数据库名"
SQL server连接方法:
set adocon=server.createobject("adodb.recordset")
adocon.Open"Driver={SQL Server};Server=(Local);UID=***;PWD=***;"& _
"database=数据库名;"
SQL server OLE DB连接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"provider=SQLOLEDB.1;Data Source=RITANT4;"& _
"user ID=***;Password=***;"& _
"inital Catalog=数据库名"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim DB_CONNECTION_STRING, conn, rs
DB_CONNECTION_STRING = "Driver={SQL Server};server=(local);uid=username;pwd=password;database=dbname;"
set conn = Server.CreateObject("Adodb.Connection")
set rs = Server.CreateObject("Adodb.Recordset")
conn.Open DB_CONNECTION_STRING
rs.ActiveConnection = conn
DB_CONNECTION_STRING = "Driver={SQL Server};server=(local);uid=username;pwd=password;database=dbname;"
set conn = Server.CreateObject("Adodb.Connection")
set rs = Server.CreateObject("Adodb.Recordset")
conn.Open DB_CONNECTION_STRING
rs.ActiveConnection = conn
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询