OPENQUERY running stored procedure twice

  • Hey All,

    I am using openquery to run a MySQL stored procedure that writes to a table in the MySQL db. The issue that is happening is that this store procedure runs twice when called only once.

    It is causing it to fail due to a primary key constraint on the table.

    select * from openquery(mysql_proddb,'call productiondb.GET_ITEM_ALL');

    Any help would be greatly appreciated.

    Thank you.

  • I suspect that the duplicate call could be due to metadata discovery.

    Try changing the "Lazy Schema Validation" property to "True" on the linked server properties page.

    -- Gianluca Sartori

  • It looks like this solution would work, unfortunately we do not have the enterprise edition of sql server. Is there another way of doing this? We are using the standard edition.

    Thank you.

  • danielgostrer (4/3/2012)


    Hey All,

    I am using openquery to run a MySQL stored procedure that writes to a table in the MySQL db. The issue that is happening is that this store procedure runs twice when called only once.

    It is causing it to fail due to a primary key constraint on the table.

    select * from openquery(mysql_proddb,'call productiondb.GET_ITEM_ALL');

    Any help would be greatly appreciated.

    Thank you.

    Shouldn't you just be using this?

    EXEC('CALL productiondb.GET_ITEM_ALL') AT mysql_proddb; Does this result in the same problem?

    Jared
    CE - Microsoft

  • thats great! works like a charm.

  • Glad to help!

    Jared
    CE - Microsoft

  • Hi Jared,

    Nice to see the solution here, In may case same issue with MSSQL Linked server, do you have any idea to solve this as well !

    I am calling like:

    SELECT *

    FROM OPENROWSET('MSDASQL','DRIVER={SQL Server};SERVER=192.168.0.1;UID=user;PWD=pass',

    'Exec DB.dbo.SPA_TEST ''1'' ')

    the Above Query Executed twice, What can i do ??

  • raghu_ktm (4/23/2012)


    Hi Jared,

    Nice to see the solution here, In may case same issue with MSSQL Linked server, do you have any idea to solve this as well !

    I am calling like:

    SELECT *

    FROM OPENROWSET('MSDASQL','DRIVER={SQL Server};SERVER=192.168.0.1;UID=user;PWD=pass',

    'Exec DB.dbo.SPA_TEST ''1'' ')

    the Above Query Executed twice, What can i do ??

    Are you not able to use the example I gave and apply it to your own? It looks like your setup is not to a linked server, but using a direct connection string. Not sure "exactly" on how to adapt this as I have only used this with a linked server.

    Jared
    CE - Microsoft

  • raghu_ktm (4/23/2012)


    Hi Jared,

    Nice to see the solution here, In may case same issue with MSSQL Linked server, do you have any idea to solve this as well !

    I am calling like:

    SELECT *

    FROM OPENROWSET('MSDASQL','DRIVER={SQL Server};SERVER=192.168.0.1;UID=user;PWD=pass',

    'Exec DB.dbo.SPA_TEST ''1'' ')

    the Above Query Executed twice, What can i do ??

    You could try to include SET FMTONLY OFF; before the EXEC, but I'm not sure this will help.

    -- Gianluca Sartori

  • I have tried on both way, but Procedure runs Twice in both case.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply