使用VBA连接MS Access中的SQL Server视图

时间:2016-02-03 13:44:14

标签: sql-server vba ms-access odbc

我在SQL Server中创建了一个View(dbo.ViewMySQL),现在想从MS Access中使用ADO查询它,连接字符串如下所示:

    cs = "Driver={SQL Server};"
    cs = cs & "Server=IP,port;"
    cs = cs & "Database=database_name;"

con.Open cs, "user", "password"

我尝试了以下SQL语句:

strQry = "select * from dbo_ViewMySQL"
strQry = "select * from viewMySQL"
strQry = "select * from [dbo].[viewMySQL]"
strQry = "select * from [db-name].[dbo].[viewMySQL]"

错误消息显示对象名称无效

  

Laufzeitffehler'-2147217865(80040e37)':[Microsoft] [ODBC SQL Server   驱动程序] [SQL Server]UngültigerObjektname'dbo_ViewMySQL'

对于strQry = "select * from tbl_Test"和其他表格,但不适用于视图,为什么会这样?

谢谢

0 个答案:

没有答案