查询表获取无效的对象名称“用户”

时间:2019-08-26 18:41:08

标签: sql-server asp-classic

由于在我的网站上使用MS Access数据库收到的所有麻烦,我现在正尝试按照你们的建议转换为SQL。

经过无数次尝试,终于可以使连接字符串工作,但是,尝试访问该表时遇到了问题。我托管在Godaddy Windows服务器上,并使用SSMS创建数据库。另外,Godaddy有一个名为myLittleAdmin的程序,数据库可以正常运行。我收到的错误提示:

  

用于SQL Server的Microsoft OLE DB提供程序错误'80040e37'   无效的对象名称“用户”。

我为表尝试了几种不同的名称,所有名称都具有相同的结果。这是代码。

<%
db_server = "my_server"
db_name = "my_db-name"
db_username = "my_username"
db_userpassword = "my_password"
db_fieldname = "my_fieldname"
db_tablename = "my_tablename"
db_schema = "my_schema"

'Establish a connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("Provider=SQLOLEDB; Data Source=" & db_server & "; Inital catalog=" & db_name & "; User ID=" & db_username & "; password=" & db_userpassword & ";")

'Test the connection to make sure it is available and it's open.
If IsObject(conn) then
 response.write "The connection is active!<br />"
 if conn.State = 1 then
   response.write "A connection is made, and is open.<br />"
 end if
end if

'Query the tables I need
Set rs= conn.execute("SELECT  * FROM [" & db_schema & "].[" & db_tablename & "]")

rs.moveFirst
While Not rs.EOF

response.write ucase(db_fieldname) & ": " & rs.Fields(db_fieldname) & "<br />"

rs.movenext
wend
rs.close

Set conn = nothing
%>

1 个答案:

答案 0 :(得分:0)

是的!我终于弄明白了。我们正朝着正确的方向前进,但是select语句还需要一个值。数据库名称位于select语句中。这就是对我有用的。

EX:db_name.db_schema.db_tableName

替换下面的“ Set rs =“行上方”

Set rs= conn.execute("SELECT  * FROM [" & db_name & "].[" & db_schema & "].[" & db_tablename & "]")

感谢您对BillRuhl和Adan Yan的帮助!