Mysql linked server queries

hello everyone, after spending most of the day trying to figure this out i hope that you guys with more experience can provide some suggestions. i have been experimenting with the a linked server (MYSQL 5) and managed to get all the select queries to work
fine, but the insert is giving me troubles. MSSQL is 2008 R2, the odbc connector is the most recent.
so here is some useful testing material:
-- Table structure for myTest on the MYSQL server
DROP TABLE IF EXISTS `myTest`;
CREATE TABLE `myTest` (
`id` bigint(20) NOT NULL,
`mystring` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`mydate` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Records
INSERT INTO `myTest` VALUES ('1', 'string1', '2009-04-17 13:11:41');
INSERT INTO `myTest` VALUES ('2', 'strin2', '2009-04-17 13:12:48');
INSERT INTO `myTest` VALUES ('3', 'string3', '2009-12-09 12:29:48');
INSERT INTO `myTest` VALUES ('4', 'nostring', '2009-12-18 12:29:48');
INSERT INTO `myTest` VALUES ('5', 'stfing5', '2010-07-17 16:40:00');
then i copied the data from mysql to MSSQL and made up new data and copied it into the 'local' copy of the mysql table:
-- copy stuff from mysql
select *
into [msTest]
from openquery(MYSQL, 'select * from myTest');
--make a copy and change a row for this example
select * into [msTestCopy]
from [msTest];
UPDATE [msTestCopy]
SET [id] = 10
,[mystring] = 'sadfasdfas'
,[mydate] = '2009-04-17 14:11:41.0000000'
where [ID] =1;
-- insert new row in the imported table
declare @myId as int;
set @myId=10;
insert into [msTest] ([ID],[mystring],[mydate])
select T1.[ID],
T1.[mystring],
T1.[mydate]
from [msTestCopy] T1
where T1.[ID] = @myId;
Then i tried an update query which was successful:
UPDATE OPENQUERY (MYSQL, 'SELECT mystring FROM mydatabase.myTest WHERE id = 1')
SET mystring = 'sadfasdfas';
Now this is where things just do not work. i tried an insert with the following:
-- insert in mysql
insert OPENQUERY(MYSQL, 'SELECT * FROM myTest')
select * FROM [dbo].[msTest] T1
where T1.[ID] = @myId;
the error returned is not very useful"
Msg 7399, Level 16, State 1, Line 5
The OLE DB provider "MSDASQL" for linked server "MYSQL" reported an error. The provider did not give any information about the error.
Msg 7343, Level 16, State 2, Line 5
The OLE DB provider "MSDASQL" for linked server "MYSQL" could not INSERT INTO table "[MSDASQL]". Unknown provider error.
then i went back to basics and tried the following
insert OPENQUERY(MYSQL, 'SELECT * FROM myTest')
values (7,'sadfasdfas','2009-04-17 14:11:41.0000000')
 similar error as a result:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "MYSQL" reported an error. The provider did not give any information about the error.
Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "MSDASQL" for linked server "MYSQL" could not INSERT INTO table "[MSDASQL]". Unknown provider error.
Does anyone have any clue of what is happening and how i could solve it?

If I use the above syntax:
EXEC master.dbo.sp_addlinkedserver @server='MYSQL', @srvproduct='NAME OF MYSQL ODBC',
@provider='MSDASQL', @provstr='DRIVER={MySQL ODBC 5.1
Driver};SERVER=SERVER IP;Port=3306;USER=myUid;PASSWORD=myPassword;OPTION=3;DATABASE=photo;'
the linked server creates properly, but it won't even let me run this statement anymore:
select * FROM OPENQUERY(MYSQL, 'SELECT * FROM photo.tag_type');
It give this error:
/* OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQL".  */
If I add this to the create statement @datasrc='MYSQL_MAIN' -- this being the name of the MySQL ODBC, therefore looking like this:
EXEC master.dbo.sp_addlinkedserver @server='MYSQL', @srvproduct='MYSQL_MAIN',
@provider='MSDASQL',@datasrc='MYSQL_MAIN', @provstr='DRIVER={MySQL ODBC 5.1
Driver};SERVER=SERVER_IP_ADDRESS;Port=3306;USER=myUID;PASSWORD=#####;OPTION=3;DATABASE=photo;'
I can at least run the above select statement, but I still get the error when running the insert statement.
Insert statement:
INSERT OPENQUERY(MY_SQL, 'SELECT * FROM photo.tag_type') VALUES (1, 'test');
Error:
/* OLE DB provider "MSDASQL" for linked server "MY_SQL" returned message "[MySQL][ODBC 5.1 Driver][mysqld-5.0.48-log]Commands out of sync; you can't run this command now".
Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "MSDASQL" for linked server "MY_SQL" could not INSERT INTO table "[MSDASQL]".  */
So can you please specify your exact syntax for this create linked server query and maybe a sample insert?  Which version of MySQL are you running?  I have tried a lot of different things and even read this post, http://bugs.mysql.com/bug.php?id=39965 with
no luck, please help.
Thanks

Similar Messages

  • How and Where linked server queries are processing ?

    Hi experts,
     Its my curiosity, i want to know where the linked server queries are running.I create linked server in local server. i am accessing one table,How the query is processing and how the it forming result set ?
    pls guide me.

    Hello,
    Please read below it might be helpful. Query would be processed at destination end if you are querying oracle database, SQL server will use Linked server and OLEDB provider for Oracle to connect to Oracle and then run query there and bring back result
    to you.
    Linking Server
    Below discussion might Interest you
    Where linked server queries are actually processed
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • How to create a view on SQLServer 2008 as an OPENQuery select to a MYSQL linked server

    I am trying to create a view on SQLServer through Management Studio based on data on a MYSql server.
    I have created the Linked server and I am able to query all data.
    Using the syntax select * from OPENQUERY (linkedServer, 'select * from MYSQL-table') - This works fine
    What I am trying to do now is issue the following statement
    create view ViewnameToBeCreatedOnSQLServer
       as select * from OPENQUERY (linkedServer, 'select * from MYSQL-table')
    When I run this from SSMS I get the following error
    OLE DB provider "MSDASQL" for linked server "TESTTSC2" returned message "[MySQL][ODBC 5.1 Driver][mysqld-5.0.95-log]Table 'FP.M3' doesn't exist".
    Msg 7350, Level 16, State 2, Procedure FPMaster3, Line 2
    Cannot get the column information from OLE DB provider "MSDASQL" for linked server "TESTTSC2".
    The account I am using has create view privs and alter schema privs on the SQlServer side. I am assuming there are not isues on the MYSQL server side since I am able to successfully run the select statement using OPENQUERY.  There must be one small
    piece I am missing. has anyone experienced the same problem and were you able to find a solution?

    All the configurations seem to be in place correctly since I can SELECT any data with no issues. The statement   
    select * from OPENQUERY (linkedServer, 'select * from MYSQL-table')
    works fine and I can change the table I am selecting from which all return data. Therefore, the objects all exists in MYSQL.
    The DSN is set up, the linked Server is good, the provider is set up, the DB account has all privs.
    It only fails when I try to create the view on SQLServer as a select from a remote table accessed via the linked MYSQL server. I connect to SQLServer with DB account PS which has full privs including CREATE VIEW and ALTER SCHEMA. The MYSQL pass-through account
    has read access to all objects in the MYSQL schema. I am trying to figure out if I might be missing some little part of this puzzle when trying to create a new object (CRESTE VIEW) vs. just reading the data (SELECT).
    The kicker in all this is that I did create a view on SQLServer in this manner about a year ago and I am able to see the view definition and that view still works! So, this is quite interesting that I am not able to create a new object.
    If there any specific information I could provide which might help, I am happy to do that. Just did not want to provide the details on all of the puzzle pieces if it can be avoided but if it comes to that then that's OK also.
    Thanks very much! I appreciate your help.

  • Memory leak issue with link server between SQL Server 2012 and Oracle

    Hi,
    We are trying to use the linked server feature with SQL Server 2012 to connect SQL server and Oracle database. We are concerned about the existing memory leak issue.  For more context please refer to the link.
    http://blogs.msdn.com/b/psssql/archive/2009/09/22/if-you-use-linked-server-queries-you-need-to-read-this.aspx
    The above link talks about the issues with SQL Server versions 2005 and 2008, not sure if this is still the case in 2012.  I could not find any article that talks about if this issue was fixed by Microsoft in later version.
    We know that SQL Server process crashes because of the third-party linked server provider which is loaded inside SQL Server process. If the third-party linked server provider is enabled together with the
    Allow inprocess option, the SQL Server process crashes when this third-party linked server experiences internal problems.
    We wanted to know if this fixed in SQL Server 2012 ?

    So your question is more of a information type or are you really facing OOM issue.
    There can be two things for OOM
    1. There is bug in SQL Server which is causing the issue which might be fixed in 2012
    2. The Linked server provider used to connect to Oracle is not upto date and some patch is missing or more recent version is to be used.  Did you made sure that you are using latest version.
    What is Oracle version you are trying to connect(9i,10g, R2...)
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Tune Linked Server

    Dear Experts,
    Could you please list out possible things for performance tuning of SQL server linked server.
    Thanks in advance

    If you are asking about tuning the Linked server queries, then the below are my best picks:
    Linchi Shea
    BRAD MCGEHEE

  • MySQL ODBC driver (32 bit) linked server, architecture mismatch

    Hello,
    I am trying to create a linked server in SQL 2012 Management Studio with a MySQL external server. I have used the 32bit ODBC driver as instructed by the developer, following this rule:
    To manage a data source that connects to a 32-bit driver under 64-bit platform, use c:\windows\sysWOW64\odbcad32.exe.
    My connection is fine using the ODBC connector, but when I try to create the linked server I get an architecture mismatch error: The specified DSN contains an architecture mismatch between the Driver and Application Error 7303.
    Can someone help?
    Best regards
    Kostas
    Kostas Backas-Systemgraph Technologies

    Hello,
    What's the bit verison of the SQL Server ?
    Based on your description, you create a DSN connect to MySQL database with 32 bit MySQL ODBC driver under 32bit ODBC Administrator tool (sysWOW64\odbcad32.exe).
    When you create linked server on SQL Server instance, it will use 64 bit Microsoft OLE DB Provider for ODBC Drivers if the bit version of SQL Server is 64 bit. That may cause the error you received. In that case, please download 64bit MySQL ODBC driver and
    create a DSN with 64 bit ODBC Administrator tool.
    Reference: http://dev.mysql.com/downloads/connector/odbc/
    If I have any misunderstanding, please correct me.
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • Facing problem in distributed queries over Oracle linked server

    Hi,
    I have a SQL Server 2005 x64 Standard Edition SP3 instance. On the instance, we had distributed (4 part) queries over an Oracle linked server running fine just a few hours back but now they have starting taking too long. They seem to work fine when OPENQUERY
    is used. Now I have a huge number of queries using the same mechanism and is not feasible for me to convert all queries to OPENQUERY, please help in getting this resolved.
    Thanks in advance.

    Hi Ashutosh,
    According to your description, you face performance issues with distributed queries and
    it is not feasible for you to convert all queries to
    OPENQUERY. To improve the performance, you could follow the solutions below:
    1. Make sure that you have a high-speed network between the local server and the linked server.
    2. Use driving_site hint. The driving site hint forces query execution to be done at a different site than the initiating instance. 
    This is done when the remote table is much larger than the local table and you want the work (join, sorting) done remotely to save the back-and-forth network traffic. In the following example, we use the driving_site hint to force the "work"
    to be done on the site where the huge table resides:
    select /*+DRIVING_SITE(h)*/
    ename
    from
    tiny_table t,
    huge_table@remote h
    where
    t.deptno = h.deptno;
    3. Use views. For instance, you could create a view on the remote site referencing the tables and call the remote view via the local view as the following example.
    create view local_cust as select * from cust@remote;
    4. Use procedural code. In some rare occasions it can be more efficient to replace a distributed query by procedural code, such as a PL/SQL procedure or a precompiler program.
    For more information about the process, please refer to the article:
    http://www.dba-oracle.com/t_sql_dblink_performance.htm
    Regards,
    Michelle Li

  • Linked Server and Distributed Queries  in Oracle

    In MSSQL, Linked Server and Distributed Queries provide SQL Server with access data from remote data sources. How about in Oracle ?
    I have a table A at Server A and table B at Server B, i wanna join these two table together. How can i do this in Oracle ?

    Use a database link: http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5005.htm
    For instance, if you have created on database A a link to database B with name 'database_b'
    you can use
    select * from table@database_b

  • SQL 2008 Problem Calling an SP on an Oracle 10G Linked Server

    Hi everyone
    I've read through a number of posts on many sites about this issue but haven't found anything that has helped me so far. The machine I'm using is running Microsoft SQL Server 2008 64bit and the linked server I've created to Oracle 10G is using OraOLEDB.Oracle. If I test the connection in SQL Management Studio it succeeds and for any queries I have using OpenQuery to select from the Oracle DB I have no problem getting results.
    The Oracle 32bit client and 64bit client versions are installed on the machine.
    My problem is that I need to exec an Oracle SP which in turn inserts into various Oracle tables. I previously had this all working fine on 32bit SQL Server 2000 installation connected to Oracle 10G. Using the same code in SQL Server 2008 I get the following error:
    Msg 7357, Level 16, State 2, Line 1
    Cannot process the object "{CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, 'BLPO0099998', 'BLPO0099998', '', '', 39804, 21883, 'BLPO0099998', 249, 1, 950, 'Main', 190506, 37336, '1', TO_DATE( '20090706','YYYYMMDD' ), TO_DATE( '20090706','YYYYMMDD' ), 'INCOMPLETE',37336, {RESULTSET 1, P_Success})}". The OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" indicates that either the object has no columns or the current user does not have permissions on that object
    The call is made by the following piece of code in SQL:
    SET @execCmd = N'SELECT
    P_Success
    FROM
    OPENQUERY( ORACLE, '''+ @oracleCmd + ''')';
    EXECUTE (@execCmd);
    Where @oracleCmd = {CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, ''BLPO0099998'', ''BLPO0099998'', '''', '''', 39804, 21883, ''BLPO0099998'', 249, 1, 950, ''Main'', 190506, 37336, ''1'', TO_DATE( ''20090706'',''YYYYMMDD'' ), TO_DATE( ''20090706'',''YYYYMMDD'' ), ''INCOMPLETE'',37336, {RESULTSET 1, P_Success})}
    I also tried using the below snippet from another post I found and got no joy either.
    declare @result varchar(255)
    exec ('BEGIN
    ?:= your_SP_Name(''arg1'', ''arg2'', etc);
    END;
    ',@result OUTPUT) at your_LinkedServerName;
    select @result;
    OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" returned message "ORA-06550: line 3, column 7:
    PLS-00222: no function with name 'INTF_TW_PO_REQ_INTERFACE' exists in this scope
    ORA-06550: line 3, column 1:
    PL/SQL: Statement ignored".
    I can't figure out why it doesn't work in SQL 2008 when it worked fine in SQL 2000 - PLEASE HELP!
    Thank you
    Alida Hope

    Why development on 10g and production on 8i? Either both should be 8i or both should be 10g.
    If you will keep production on 8i and development on 10g then you cannot stop such errors as there are features that are enabled by default in 10g and both the versions have very big differences.
    Just go ahead and install 8i.

  • OLEDB provider VFPOLEDB for linked server returned message "Invalid path or file name"

    Hello,
    I'm hoping someone can shed some light on this.  I'd researched this error for days, reading all the post in this forum, however none of them address my issue.
    We use VFP 9 .dbf tables (free tables).  I setup a linked server to query the tables.  As first we were not able to view the tables in SQL Server Mgmt Studio (MSMS) until I sorted out the permissions.  I can query the tables if I copy over
    to the server so they are local tables.  However, across the network I am continually getting the error above and the following error:
    "Cannot initialize the data source object of OLE DB provider VFPOLEDB for linked server XXX."
    Here are the steps I've performed...
    Installed a 32 bit instance of SQL Server Express 2008 R2 using Windows Authentication on server 2 (the 64 bit instance could not see the VFP OLE DB provider, as we all know, because the provider is only 32 bit)
    Installed the latest VFP OLE DB from http://www.microsoft.com/en-us/download/details.aspx?id=14839.
    In the VFPOLEDB provider, I enabled Nested queries, Level zero only, Allow inprocess, and Supports 'Like' operator.
    Setup a linked server using the following query:
    EXEC master.dbo.sp_addlinkedserver
    @server = N'LinkedAC',
    @srvproduct = N'Visual FoxPro 9',
    @provider = N'VFPOLEDB',
    @datasrc = N'"\\server1\share\TIW\KOKAC"',
    @provstr = N'VFPOLEDB.1'
    At first I could not view the tables when expanding default>Tables, it failed due to a "catastrophic failure".  That can't be good ;-).  After digging around, I surmised it was because I'd set the SQL Instance to run as NT Authority\NetworkService.
    I created a new user, LinkedVFP, and added to the SQL Instance (using Windows Authentication), mapped the user to the master database with the db_datareader role.  I also added the LinkedVFP user to the network share.  I was then able to browse
    the tables in MSMS and query the data when local, but still not across the network.
    I'm using Crystal Reports to try and query the data from my local workstation using SELECT * FROM OPENQUERY(mylinkedserver, 'select * from table1').  This produces the two errors I mentioned above.
    To clarify, the VFP tables are on server 1 and the linked server is on server 2.  I've read about service account delegation, but unclear if this is the issue.  I went into our domain controller (neither server 1 or 2), AD User and Computers, and
    for server 2 I enabled 'Trust this computer for delegation to any service (Kerberos only)'. 
    Can anyone shed some light on this for me?
    Thanks!
    Aaron McVanner

    Hi Aaron,
    Thank you for your question. I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    If you have any feedback on our support, please click
    here.
    Regards,
    Elvis Long
    TechNet Community Support

  • Linked Server [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    Hi  I have SQL2012 installed on my local machine and have also installed MySQL 5.6.23 installed with a test database.
    I also have my SQL connector installed and MYSQL ODBC Driver 3.51.   
    Which happily connects to the Mysqldb.
    The Datasource Name : mySQL conn
    TCP/IP Server : localhost and Port :3306
    User root
    with pwd
    On the SQL side I have used the following
    EXEC master.dbo.sp_addlinkedserver
      @server = N'MYSQLSRV',
      @srvproduct=N'mySQL conn',
      @provider=N'MSDASQL',
      @datasrc=N'mySQL conn'
    However when I try to selet using open query
    SELECT * FROM OPENQUERY ( [MYSQLSRV], 'SELECT * FROM students' )
    it comes back with
    OLE DB provider "MSDASQL" for linked server "MYSQLSRV" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
    Msg 7303, Level 16, State 1, Line 1
    Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQLSRV".
    I cant understand what I have done wrong .   Any help in this would be great as Ive hit a bit of a brick wall

    Hi Robert3975,
    In addition to other post, please also note the following things.
    1. If you use the 32-bit driver on a 64-bit machine, please run the 32bit version of "odbcad32.exe" by running "c:\Windows\SysWOW64\odbcad32.exe"
     from Start/Run menu and
    create your ODBC DSN. However, for the 64-bit driver, use c:\windows\system32\odbcad32.exe to create your ODBC DSN. For more details, please review this similar
    thread.
    2. Expand the folder Providers under Linked server directory in SSMS and go to properties of MSDASQL provider and configure it properly as described in this blog:
    Creating Linked server to MYSQL from SQL Server.
    Thanks,
    Lydia Zhang
    If you have any feedback on our support, please click
    here.
    Lydia Zhang
    TechNet Community Support

  • Left outer join on linked server

    Hi,
    I am migrating large amounts of data from Oracle database to SQL Server database, through a linked server.
    When I use LEFT JOIN, the SQL server execution plan shows that the query that merges tables is not executed remotely (i.e. the data from both tables that I am trying to join is fetched on SQL server and joined on SQL server instead of being joined on Oracle and fetched after that), while queries using INNER JOIN fully execute on the remote server. I am trying to join remote Oracle database tables and the result of the join is supposed to be populated in a local table.This LEFT JOIN issue significantly enlarges the amount of a query execution time.
    Can someone explain why is this so and suggest a solution? I tried using OPENQUERY but the results are not fetched properly because of the collation.
    Thanks in advance!

    with t1 as (
                select 1 id,to_date('1-Jan-12','dd-mon-rr') dateA from dual union all
                select 1,to_date('1-Feb-12','dd-mon-rr') from dual union all
                select 1,to_date('1-Mar-12','dd-mon-rr') from dual union all
                select 2,to_date('1-Feb-12','dd-mon-rr') from dual union all
                select 2,to_date('1-Mar-12','dd-mon-rr') from dual union all
                select 2,to_date('1-Apr-12','dd-mon-rr') from dual
         t2 as (
                select 1 id,to_date('1-Feb-12','dd-mon-rr') dateB,'a' valB from dual union all
                select 1,to_date('1-Mar-12','dd-mon-rr'),'b' from dual union all
                select 2,to_date('1-Feb-12','dd-mon-rr'),'c' from dual union all
                select 2,to_date('1-Mar-12','dd-mon-rr'),'d' from dual
    select  t1.id,
            dateA,
            max(dateB) dateB,
            max(valB) keep(dense_rank last order by dateB) valB
      from      t1
            left join
                t2
              on     t2.id = t1.id
                 and
                     dateB <= dateA
      group by t1.id,
               dateA
      order by id,
               dateA
            ID DATEA     DATEB     V
             1 01-JAN-12
             1 01-FEB-12 01-FEB-12 a
             1 01-MAR-12 01-MAR-12 b
             2 01-FEB-12 01-FEB-12 c
             2 01-MAR-12 01-MAR-12 d
             2 01-APR-12 01-MAR-12 d
    6 rows selected.
    SQL> SY.

  • Query using link server to an Oracle database failswhile similar query works

    I have two queries almost the same that use a link to an Oracle database. One works ok, the other is a copy of the first with a few fields selects removed.  The first one works fine, the copy fails with: Cannot get the data of the row from the OLE DB
    provider "OraOLEDB.Oracle" for linked server "linkname".
    They are so similar, why would one work but not the other? 
    First query, this one works:
    SET
    ANSI_NULLS ON
    GO
    SET
    QUOTED_IDENTIFIER ON
    GO
    CREATE
    PROCEDURE [dbo].[procedure_name]
    -- Add the parameters for the stored procedure here
    @Begindate  Datetime,
    @Enddate Datetime
    AS
    BEGIN
    --SET NOCOUNT ON added to prevent extra result sets from
    --interfering with SELECT statements.
    SET NOCOUNT
    ON;
    -- Insert statements for procedure here
    select p.patientid, p.testid,
    mdx."Dx_4", td.acquisitiondatetime_dt, td.democompletedatetime_dt,
    td.editdatetime_dt,
    CAST(STUFF(STUFF(mn."Arrival_Time_9",
    9, 0,
    ' '), 12, 0,
    AS datetime)
    as Arrival_date,
    CAST(STUFF(STUFF(mt."Comp_D_T_22",
    9, 0,
    ' '), 12, 0,
    AS datetime)
    as Order_date, td.confirmdatetime_dt
    (CAST(DATEDIFF
    (MINUTE,
    CAST (STUFF
    (STUFF
    (MN."ARRIVAL_TIME_9", 9,0,
    ' '), 12, 0,
    AS DATETIME), TD.DEMOCOMPLETEDATETIME_DT) 
    as char(10))
    + 'min')
    AS "ARRIVAL TO COMPLETE",
    (CAST(DATEDIFF
    (MINUTE,
    CAST (STUFF
    (STUFF
    (MT."COMP_D_T_22", 9,0,
    ' '), 12, 0,
    AS DATETIME), TD.DEMOCOMPLETEDATETIME_DT)
    as char(10))
    + 'min') 
    AS "ORDER TO COMPLETE"
    from linknametosqldb.sqldbname.dbo.tstpatientdemographics
    as p inner
    join linknametosqldb.sqldbname dbo.tsttestdemographics
    as td on p.testid
    = td.testid
    left
    outer join linknametooracledb."M01Tab01_Main" mn
    on td.visitnumber
    = mn."Pt_Acct_5"
    inner
    JOIN linknametooracledb."M01Tab06_Ord" mt
    ON mn."Master_Recid_1"
    = mt."Master_Recid_1"
    inner
    join linknametooracledb."M01Tab09_Dx" mdx
    on mn."Master_Recid_1"
    = mdx."Master_Recid_1"
    where td.location
    in (2, 4)
    and mt.order_4
    like 'EKG%' 
    and mdx."Dx_4"
    like '%Chest Pain%'
    and
    (td.acquisitiondatetime_dt
    >= @Begindate and td.acquisitiondatetime_dt
    < @Enddate)
    order
    by p.patientfullname_last, p.patientfullname_first
    END
    GO
    Second query, copied from first with some fields selects removed, this does not work:
    SET
    ANSI_NULLS ON
    GO
    SET
    QUOTED_IDENTIFIER ON
    GO
    CREATE
    PROCEDURE [dbo].[procedure_name_2]
    -- Add the parameters for the stored procedure here
    @Begindate  Datetime,
    @Enddate Datetime
    AS
    BEGIN
    --SET NOCOUNT ON added to prevent extra result sets from
    --interfering with SELECT statements.
    SET NOCOUNT
    ON;
    -- Insert statements for procedure here
    select p.patientid, mdx."Dx_4",
    td.democompletedatetime_dt,
    CAST(STUFF(STUFF(mn."Arrival_Time_9",
    9, 0,
    ' '), 12, 0,
    AS datetime)
    as EDIS_Arrival_date,
    (CAST(DATEDIFF
    (MINUTE,
    CAST (STUFF
    (STUFF
    (MN."Arrival_Time_9", 9,0,
    ' '), 12, 0,
    AS DATETIME), TD.DEMOCOMPLETEDATETIME_DT) 
    as char(10))
    + 'min')
    AS "ARRIVAL TO COMPLETE"
    from linknametosqldb.dbo.tstpatientdemographics
    as p inner
    join linknametosqldb.dbo.tsttestdemographics
    as td on p.testid
    = td.testid
    left outer
    join linknametooracledb."M01Tab01_Main" mn
    on td.visitnumber
    = mn."Pt_Acct_5"
    inner
    JOIN linknametooracledb."M01Tab06_Ord" mt
    ON mn."Master_Recid_1"
    = mt."Master_Recid_1"
    inner
    join linknametooracledb M01Tab09_Dx" mdx
    on mn."Master_Recid_1"
    = mdx."Master_Recid_1"
    where td.location
    in (2, 4)
    and mt.order_4
    like 'EKG%' 
    and mdx."Dx_4"
    like '%Chest Pain%'
    and
    (td.acquisitiondatetime_dt
    >= @Begindate and td.acquisitiondatetime_dt
    < @Enddate)
    order
    by p.patientid
    END
    GO
    Thanks very much for any help with this.

    * Consider putting parentheses around the 3 oracle tables so the 3 of them can possibly be treated as a unit.  Assuming there's some performance impact due to the linked server, this MIGHT help, may do a little joining over on the Oracle side of
    the world.  In either case, it's a little cleaner.  They syntax below, including a few extra line breaks for clarity, should be correct.  (try the change to the ON clause suggested above too, though).
    The parentheses will not help much. SQL Server will remote (as the term is) the query to the Oracle instance if this appears to have a lower cost and there is nothing the blocks remoting.
    On the other hand, OPENQUERY can be an alternative to ensure that this happens:
     left outer join
        OPENQUERY (linknametooracledb,
                   'SELECT ...
                    FROM   "M01Tab01_Main" mn
                    JOIN   "M01Tab06_Ord" mt ON mn."Master_Recid_1" = mt."Master_Recid_1"
                    JOIN   "M01Tab09_Dx" mdx on mn."Master_Recid_1" = mdx."Master_Recid_1"') mn on td.visitnumber = mn."Pt_Acct_5"
    But this presumes that you there are no columns from the SQL Server side that are used to select data from the Oracle side. That is, the above could lead to far much data being brought across the wire.
    Then again, this does not really seem to relate to the original problem where a stored procedure was not working at all. That problem is not very easy to assist with since code post is the not the authentic code as pointed out in the thread. For instance
    inner JOIN linknametooracledb."M01Tab06_Ord"
    Has nothing to do with Oracle, but accesses a table in the schema linknametooracledb.
    I think to help dmcm, you need a really good crystal ball - at least as long he/she does not share the actual code.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Current Security Context Not Trusted When Using Linked Server From ABAP

    Hello,
    I am experiencing a head-scratcher of a problem when trying to use a Linked Server connection to query a remote SQL Server database from our R/3 system.  We have had this working just fine for some time, but after migrating to new hardware and upgrading OS, DBMS, and R/3, now we are running into problems.
    The target database is a named instance on SQL Server 2000 SP3, Windows 2000 Server.  The original source R/3 system was 4.7x2.00, also on SQL Server 2000 (SP4), Windows 2000 Server.  I had been using a Linked Server defined via SQL Enterprise Manager (actually defined when the source was on SQL Server 7), which called an alias defined with the Client Network Utility that pointed to the remote named instance.  This alias and Linked Server worked great for several years.
    Now we have migrated our R/3 system onto new hardware, running Windows Server 2003 SP1 and SQL Server 2005 SP1.  The application itself has been upgraded to ECC 6.0.  I performed the migration with a homogeneous system copy, and everything has worked just fine.  I redefined the Linked Server on the new SQL 2005 installation, this time avoiding the alias and referencing the remote named instance directly, and it tests out just fine using queries from SQL Management Studio.  It also tests fine with OSQL called from the R/3 server console, both when logged on as SAPServiceSID with a trusted connection, and with a SQL login as the schema owner (i.e., 'sid' in lowercase).  From outside of R/3, I cannot make it fail.  It works perfectly.
    That all changes when I try to use the Linked Server within an ABAP application, however.  The basic code in use is
    EXEC SQL.
       SET XACT_ABORT ON
       DELETE FROM [SERVER\INSTANCE].DATABASE.dbo.TABLE
    ENDEXEC.
    The only thing different about this code from that before the upgrade/migration is the reference to [SERVER\INSTANCE] which previously used the alias of just SERVER.
    The program short dumps with runtime error DBIF_DSQL2_SQL_ERROR, exception CX_SY_NATIVE_SQL_ERROR.  The database error code is 15274, and the error text is "Access to the remote server is denied because the current security context is not trusted."
    I have set the "trustworthy" property on the R/3 database, I have ensured SAPServiceSID is a member of the sysadmin SQL role, I've even made it a member of the local Administrators group on both source and target servers, and I've done the same with the SQL Server service account (it uses a domain account).  I have configured the Distributed Transaction Coordinator on the source (Win2003) system per Microsoft KB 839279 (this fixed problems with remote queries coming the other way from the SQL2000 system), and I've upgraded the system stored procedures on the target (SQL2000) system according to MS KB 906954.  I also tried making the schema user a member of the sysadmin role, but naturally that was disastrous, resulting in an instant R/3 crash (don't try this in production!), so I set it back the way it was (default).
    What's really strange is no matter how I try this from outside the R/3 system, it works perfectly, but from within R/3 it does not.  A search of SAP Notes, SDN forums, SAPFANS, Microsoft's KnowledgeBase, and MSDN Forums has not yielded quite the same problem (although that did lead me to learning about the "trustworthy" database property).
    Any insight someone could offer on this thorny problem would be most appreciated.
    Best regards,
    Matt

    Good news! We have got it to work. However, we did it in something of
    a backwards way, and I'm sure you'll laugh when you see how it was done. Also, the solution depends upon the fact that the remote server is still using SQL Server 2000, and so doesn't have quite so many restrictions placed upon it for distributed transactions and Linked Servers as SQL Server 2005 now does.
    At the heart of the solution is the fact that the Linked Server coming FROM the remote server TO our SAP system works fine. Finally, coupled with the knowledge that using DBCON on the SAP side to the remote server also does actually provide a connection (see Notes 323151 and 738371), we set up a roundabout way of achieving our goal. In essence, from ABAP, we set up the DBCON connection to the remote server, at which point all the Native SQL commands execute in the context of the remote server. From within that connection, we
    reference the tables in SAP via the Linked Server defined on the remote
    server, as if SAP were the remote server, selecting data from SAP and inserting it into the remote (but apparently local to this connection) tables.
    So, to spell it out, we define a Linked Server on the remote server pointing back to the SAP server as SAPSERV, with a SQL login mapping defined on the remote system pointing back to a SQL login in the SAP database. We also define a connection to the remote server from SAP using DBCON, using that remote SQL login for authentication.
    Then, in our ABAP code, we simply do something along the lines of
    exec sql.
       set connection 'REMOTE'
    endexec.
    exec sql.
       connect to 'REMOTE'
    endexec.
    exec sql.
       insert into REMOTE_TABLE
          select * from SAPSERV.SID.sid.SAP_TABLE
    endexec.
    exec sql.
       commit
    endexec.
    exec sql.
       disconnect 'REMOTE'
    endexec.
    This is, of course, a test program, but it demonstrated that it worked,
    and we were able to see that entries were appropriately deleted and inserted in the remote server's table. The actual program for use is a little more complex, in that there are about four different operations at different times, and we had to resolve the fact that the temp table SAP_TABLE was being held in a lock by our program, resulting in a deadly embrace, but our developer was able to work that out, and all is now well.
    I don't know if this solution will have applicability to any other customers, but it works for us, for now.
    SAPSERV, REMOTE, REMOTE_TABLE, and SAP_TABLE are, of course, placeholder names, not the actual server or table names, so as not to confuse anyone.
    Best regards,
    Matt

  • SQL linked server twice as slow in Windows 7 as XP

    We have a transaction based synchronization from SQL Server to Oracle, i.e. both must commit or rollback in one distributed transaction. We achieved this using MSSQL Linked Server using the Oracle Provider for OLE DB and triggers running openquery for speed.
    The SQL Sever 2008 was on XP (doesn't need a server) and the Oracle 11g was on Red Hat 5EL. In testing from the first trigger firing to the last trigger finishing, a save test took ~11 Seconds, not perfect but acceptable. Yet when we moved to Windows 7 this time rose to 19 Seconds.
    We contacted Microsoft support and they seen to thing it is a multi platform issue. So to prove them wrong we created an oracle DB on a Windows 7 system and ran the tests again, same issue. They will not look into the issue without us paying for premium support at an hourly rate, due to the Oracle DB. So we created one more test environment to try to prove it was a Microsoft issue and not an Oracle driver issue we created 2 SQL servers and ran tests to see if we got the same issue. We got the following results, which seems to point the finger at the Oracle OLE Driver on Win 7:
    Windows XP sync to Windows 7:
    SQL Server to Oracle = ~8 seconds
    SQL Server to SQL Server = ~6.5 seconds
    Windows 7 sync to Windows 7:
    SQL Server to Oracle = ~19 seconds
    SQL Server to SQL Server = ~5.5 seconds
    Has anybody else found this issue and if so have they found a cause?
    We Have run NetMon and analysed the results and the packets seem to take twice as long in Win 7 as Win XP. This seemed to point to a network issue, but does not explain why 100% Microsoft is faster when synchronising Win 7 to Win 7, as opposed to Win XP to Win 7.
    I get the feeling the issue lies somewhere in the changes that were made by Microsoft in Vista in the networking protocols and configuration, causing a side affect in the OLE Driver. It could be that the driver works, but needs to be tuned with the new networking protocols from Microsoft.
    We have tried countless network settings, even the ones suggestions from MS Support made no difference at all.
    Edited by: 925129 on 03.04.2012 03:57
    Corrected a couple of types

    Hi Greg,
    Thanks for the answer, sorry for the late reply, I was away for Easter.
    What we have done is to alter the triggers to record their names, start and end times to an SQL Server table. I delete the contents of the table then run a test and run several queries to analyse the trigger data. the difference between the min start time and the max end time is how we get the total time. We run many queries over the data. I can send you the table DDL and some test run results DML, as well as, the queries I use to analyse the results.
    On top of this test we have run Microsoft's NetMon to analyse the network traffic and there it is clear that the packets take roughly twice as long in Win 7 as in Win XP, both in 32-bit and 64-bit OS versions. I know there has been some major network changes after Win XP and Microsoft are convinced this is an Oracle issue. The same OLE Driver is used for both Win 7 and Win XP OS's (excluding the one for 32-bit and one for 64-bit) and my guess is something needs to be tuned for the networking in Win 7. We have really tested this so much over the last 2 months and tried all kinds of network setting tuning in windows but nothing has worked at all.
    After creating an SQL DB to act in the place Oracle DB, the same issue was not present, so it really is a heterogeneous platform issue. In fact if the sync is SQL to SQL it is faster in Win 7 not slower.
    If you would like any of the results of our testing to see if you can spot the issue, you would be welcome.
    Guy
    Edited by: 925129 on 16-Apr-2012 05:40
    Edited by: 925129 on 16-Apr-2012 05:41

Maybe you are looking for

  • Old Cinema Display 22" won't work with DVI-ADC adapter & Mac Pro

    So, I want to use my old 22" ADC Cinema Display with my new Mac Pro with the Radeon x1900 card. And I was told to buy the DVI to ADC adapter, which I did. But it doesn't work! The adapter powers up my monitor, and it shows up in the Display settings

  • Active directory domain services stopped after removing routing and remote access role

    Hello everyone;; I am in deep trouble.. I did install routing and remote access and then  lost connection to the server remotely. Then I connected a monitor to the server and removed the role... then it asked me to restart the server . After logging

  • Systems are not visiable in monitoring graphic

    Hi friends, I am not able to view systems under monitoring graphic. the screen is showing blank. One of our PC is showing systems and self diagnostic screen, i made my system same as that system(GUI, IE, host entries, JRE) but still i am not able to

  • Video with audio, narration and soundtrack has no narration after rendering

    Hi, I edited a video and then I added a narration and a soundtrack. In the editor I see and hear exactly what I want. When I'm publishing the video though the narration is lost. I've tried with both Premiere Elements 11 and 12 with the same results.

  • Name of a portlet

    Where do you change the name of the portlet which appears in the portal ? Because the name displayed is the name of the jsp file of the portlet. Can I change it ? Thanks to help me...