Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Problem with using SQL Server linked server to MySQL database Expand / Collapse
Author
Message
Posted Sunday, January 13, 2013 12:31 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 9:35 AM
Points: 14, Visits: 51
I have a MS SQL Server that does a lot of data manipulation and staging and then I need to push those changes to a MySQL database. I've had a lot of problems using a linked server to this MySQL database but the particular problem I'm having today is related to a delete statement.

I had some issues with getting errors when running a DELETE statement that ends up deleting 0 rows based on the where clause. So I had to write what I consider to be a sloppy check because I was getting the same error when using a IF EXISTS statement. So in my below example I am certain that I will be deleting something (in my test case it was 16 records).

IF EXISTS (select * from #exists_check)
BEGIN
DELETE FROM MYSQL_LINKEDSVR...product
WHERE product_id IN (SELECT product_id from #Discontinued_Products)
END

I receive this error:

OLE DB provider "MSDASQL" for linked server "MYSQL_BFGLOCKER" returned message "Data provider or other service returned an E_FAIL status.".
Msg 7330, Level 16, State 2, Line 3
Cannot fetch a row from OLE DB provider "MSDASQL" for linked server

Now, I've seen this error a lot in a lot of other situations so it appears to be a generic error to me? Does this mean anything to anyone or could anyone explain why this legitimate delete statement is throwing and error when the several (identical except for the table name) statements run successfully?

NOTE: I get the same error when trying to update the same table.

IF EXISTS (select * from #exists_check)
BEGIN
UPDATE MYSQL_LINKEDSVR...product
SET quantity = 0
WHERE product_id IN (SELECT product_id from #OutOfStock_Products)
END

Thanks,
Derik Hammer
www.sqlHammer.com


Best Regards,
Derik Hammer
www.sqlhammer.com
Post #1406500
Posted Sunday, January 13, 2013 1:20 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:24 PM
Points: 6,826, Visits: 11,950
Could you please script out your Linked Server definition and post it here minus any sensitive information? Also, which MySQL driver, type and version, are you using?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1406508
Posted Sunday, January 13, 2013 1:46 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 9:35 AM
Points: 14, Visits: 51
As seen below I'm using "MySQL ODBC 5.1 Driver".

The only things changed below is the actual Linked Server name (to match example scripts), domain, database name, and username/password.

/****** Object:  LinkedServer [MYSQL_LINKEDSVR]    Script Date: 01/13/2013 15:43:10 ******/
EXEC master.dbo.sp_addlinkedserver @server = N'MYSQL_LINKEDSVR', @srvproduct=N'MySQL', @provider=N'MSDASQL',
@provstr=N'DRIVER={MySQL ODBC 5.1 Driver};SERVER=mydomain.com;Port=3306;USER=Manager;PASSWORD=SuperSecretPassword;OPTION=3;DATABASE=MyDatabase'
/* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'MYSQL_LINKEDSVR',@useself=N'True',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL

GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'collation compatible', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'data access', @optvalue=N'true'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'dist', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'pub', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'rpc', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'rpc out', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'sub', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'connect timeout', @optvalue=N'0'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'collation name', @optvalue=null
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'lazy schema validation', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'query timeout', @optvalue=N'0'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'use remote collation', @optvalue=N'true'
GO

EXEC master.dbo.sp_serveroption @server=N'MYSQL_LINKEDSVR', @optname=N'remote proc transaction promotion', @optvalue=N'true'
GO





Best Regards,
Derik Hammer
www.sqlhammer.com
Post #1406512
Posted Sunday, January 13, 2013 3:17 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:24 PM
Points: 6,826, Visits: 11,950
I am unable to recreate the scenario, i.e. I am able to delete from remote tables referenced by 4-part naming using an IN with a temp table to achieve a JOIN even when no rows are affected on the MySQL side.

Is there anything different about the product table? Maybe it is a storage engine thing on MySQL.

Also, what are your MSDASQL provider settings?

I have the following checked:

Nested queries
Level zero only
Allow inprocess
Supports 'like'


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1406518
Posted Sunday, January 13, 2013 6:00 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 9:35 AM
Points: 14, Visits: 51
I'm not sure if this was the information that you sought.



Best Regards,
Derik Hammer
www.sqlhammer.com
Post #1406536
Posted Sunday, January 13, 2013 9:22 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:24 PM
Points: 6,826, Visits: 11,950
I meant in the Linked Server node in SSMS Object Explorer, under Providers, right click MSDASQL and go to Properties. What do you have setup for options?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1406560
Posted Wednesday, January 16, 2013 8:15 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 9:35 AM
Points: 14, Visits: 51
I apologize for the delayed response I've been ill.

My MSDASQL settings are the same as yours.


Best Regards,
Derik Hammer
www.sqlhammer.com
Post #1407867
Posted Wednesday, January 16, 2013 8:26 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:24 PM
Points: 6,826, Visits: 11,950
How about the storage engine (e.g. InnoDB) of the tables you're having trouble with? Any patterns there?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1407872
Posted Wednesday, January 16, 2013 9:00 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 9:35 AM
Points: 14, Visits: 51
To be frank, I'm pretty good with MSSQL but I'm basically a MySQL noob.

If you could point out anything that I should be looking for I would gladly perform the investigation but this MySQL database is hosted with a 3rd party. I have rights to it but I was not the administrator that set it up and the schema was built by OpenCart so I wasn't even involved in its design.


Best Regards,
Derik Hammer
www.sqlhammer.com
Post #1407903
Posted Wednesday, January 16, 2013 9:27 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:24 PM
Points: 6,826, Visits: 11,950
Do you have a copy of MySQL Workbench installed? If you use it to connect to the database and navigate to the table there will be an indicator on one of the properties pages showing which storage engine the table is using (InnoDB, MyIsam, etc.). It's a longshot that something like a diff in the storage engine would matter in this instance but I have seen sillier things with MySQL.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1407930
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse