时间:2021-07-01 10:21:17 帮助过:59人阅读
- <br>'以下为建立connection对象连接数据库 <br>Dim conn <br>Set conn=Server.CreateObject("ADODB.Connection") <br>sql="Provider=SQLoledb;data source=WWW-2443D34E558\SQL2005;UID=;PWD=;Initial Catalog=forum;Integrated Security=SSPI" <br>conn.Open sql <br>'以下为判断是否连接 <br>If conn.state=2 Then <br>Response.Write("正在连接") <br>ElseIf conn.state=1 Then <br>Response.Write("连接已经打开") <br>Else <br>Response.Write("对不起,无法打开连接") <br>End If <br> <br>(2)、SQL SERVER用户名身份验证连接方法,此例中SQL用户名为sa ,密码******** <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>'以下为建立connection对象连接数据库 <br>Dim conn <br>Set conn=Server.CreateObject("ADODB.Connection") <br>sql="Provider=SQLoledb;data source=WWW-2443D34E558\SQL2005;UID=sa;PWD=********;Initial Catalog=forum" <br>conn.Open sql <br>'以下为判断是否连接 <br>If conn.state=2 Then <br>Response.Write("正在连接") <br>ElseIf conn.state=1 Then <br>Response.Write("连接已经打开") <br>Else <br>Response.Write("对不起,无法打开连接") <br>End If <br> <br>(3)、以上两种方法也可以用以下方式 <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName,ConnStr,Conn <br>SqlDatabaseName = "forum" 'SQL数据库名 <br>SqlUsername = "sa" 'SQL数据库用户名 <br>SqlPassword = "**********" 'SQL数据库用户密码 <br>SqlLocalName = "WWW-2443D34E558\SQL2005" 'SQL主机IP地址(服务器名) <br>ConnStr = " Password = "&SqlPassword&"; user id =" & SqlUsername&"; Initial Catalog ="&SqlDatabaseName&"; data source ="& SqlLocalName &";Provider = sqloledb;" <br>Set conn = Server.CreateObject("ADODB.Connection") <br>conn.open ConnStr <br><br>If conn.state=2 Then <br>Response.Write("正在连接") <br>ElseIf conn.state=1 Then <br>Response.Write("连接已经打开") <br>Else <br>Response.Write("对不起,无法打开连接") <br>End If <br></li><li> </li><li> </li></ol></pre></li></ol></pre>