Tuesday, December 4, 2007

How to Distributed Query on the fly

How to Distributed Query on the fly

To Distributed Query on the fly

If you have not setup your linked server or some changes has been made to the server you can issue SQL on the fly through.

set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DSN=tenderproject;UID=tenderproject;PWD=tender"

set rs=Server.CreateObject("ADODB.Recordset")

sqlstr = SELECT * FROM OPENROWSET("SQLOLEDB","192.168.0.1","RemoteUser","RemotePassword", "SELECT * FROM Database.dbo.table")

rs.open sqlstr, conn, 1,3

Notice that you only use OPENROWSET instead of the OPENQUERY statement.

No comments: