0x800a0e7d - ADODB.Recordset:无法使用连接执行 这个操作。在这种情况下,它是关闭的或无效的。
运行我的asp页面时出现此错误
Set ConnectionString = Server.CreateObject("ADODB.Connection")
ConnectionString.Open "Provider=SQLOLEDB.1; Password=pass@123;User ID=sa;Initial Catalog=USERDB; Data Source=SQL\MSSQLSERVER2014;"
Dim rs
strSQL = "SELECT * FROM user WHERE username= 'test' AND Password='test123'
rs.Open strSQL, ConnectionString
我正在使用VS 2012和SQL Server 2014,我正在通过IIS运行。
答案 0 :(得分:0)
试试这样:
'declare the variables
Dim Conn
Dim rs
Dim strSQL
'declare the SQL statement that will query the database
strSQL = "SELECT * FROM user WHERE username= 'test' AND Password='test123'"
'create an instance of the ADO connection and recordset objects
Set Conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.recordset")
'open the connection to the database
Conn.Open "Provider=SQLOLEDB.1;Password=pass@123;User ID=sa;Initial Catalog=USERDB;Data Source=SQL\MSSQLSERVER2014;"
'Open the recordset object executing the SQL statement and return records
rs.Open strSQL, Conn
...
'close the connection and recordset objects to free up resources
rs.Close
Set rs = nothing
Conn.Close
Set Conn = nothing