Is there a way to prevent SQL Server from Validating the SQL in a stored procedure during CREATE / ALTER

孤者浪人 提交于 2020-01-03 10:45:16

问题


One aspect of our system requires our SQL Server instance to talk to a MySQL Server via a linked Server Connection.

MSSQL -> LinkedServer(MSDASQL ODBC Provider) -> MySQL ODBC Connector -> MySQL DB

The Table on the linked server is called in a SPROC along the lines of

CREATE PROCEDURE DoStuff
AS

SELECT a.ID, a.Name, b.OtherProperty
FROM   MyDatabase..MyTable a
JOIN   LINKSRVR...OtherTable b
ON     a.ID = b.ID

GO

The problem is that the MySQL database lives on another network, only accessible by VPN & that the CREATE or ALTER statement breaks with the following error unless the VPN is active.

The OLE DB provider "MSDASQL" for linked server "LINKSRVR" reported an error. 
 The provider did not give any information about the error.

Cannot initialize the data source object of OLE DB provider 
"MSDASQL" for linked server "LINKSRVR".

Is there anyway to force SQL Server to just go ahead and create the SPROC with the SQL I tell it and not to try and validate if the LinkedServer is up/down.


回答1:


You'd have to "hide" the offending SQL from the compiler by placing it in a string and executing it as dynamic SQL.



来源:https://stackoverflow.com/questions/7558184/is-there-a-way-to-prevent-sql-server-from-validating-the-sql-in-a-stored-procedu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!