I have a table say Table1 on SQL Server 2014 and MySQL both.
Table1
ID INT,Code VARCHAR(100)
I created a linked server MyLinkedServer in SQL Server using "Microsoft OLEDB Provider for ODBC".
**Linked Server **
EXEC master.dbo.sp_addlinkedserver #server = N'MyLinkedServer', #srvproduct=N'MyLinkedServer', #provider=N'MSDASQL', #datasrc=N'MyLinkedServer'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'MyLinkedServer',#useself=N'False',#locallogin=NULL,#rmtuser=N'username',#rmtpassword='########'
Linked Server Settings
EXEC master.dbo.sp_serveroption #server=N'MyLinkedServer', #optname=N'data access', #optvalue=N'true'
EXEC master.dbo.sp_serveroption #server=N'MyLinkedServer', #optname=N'use remote collation', #optvalue=N'true'
EXEC master.dbo.sp_serveroption #server=N'MyLinkedServer', #optname=N'remote proc transaction promotion', #optvalue=N'true'
The linked server is created successfully and I am able to query Mysql Table in SQL Server.
Query
When I run
INSERT INTO MyLinkedServer...Table1(ID,Code) SELECT 1,'Code1'
The record is inserted. However when I start a transaction and run the INSERT, I get an error:
BEGIN TRAN
INSERT INTO MyLinkedServer...Table1(ID,Code) SELECT 1,'Code1'
COMMIT
Error:
OLE DB provider "MSDASQL" for linked server "MyLinkedServer" returned message "[MySQL][ODBC 5.3(a) Driver]Optional feature not supported".
Msg 7391, Level 16, State 2, Line 8
The operation could not be performed because OLE DB provider "MSDASQL" for linked server "MyLinkedServer" was unable to begin a distributed transaction.
What I have tried so far.
Enable XA Transactions in MSDTC
Enabled following setting in Linked Server Provider
Nested queries
Level zero only
Allow inprocess
Supports ‘Like’ Operator
I checked the following links and their suggestions however the error persists:
Distributed transactions between MySQL and MSSQL
SQL-Server and MySQL interoperability?
SQL Server and MySQL Syncing
EDIT
Additional Details:
MySQL is using InnoDB storage engine on Ubuntu machine.
I have already configured the ODBC connector and used it to configure a ODBC System Data Source which is used in the Linked Server
Theoretically this should work.
I would suggest different steps to sort this out:
Have you checked you MySql storage engine yet? It looks only InnoDB storage engine support distribute transaction per MySql document: https://dev.mysql.com/doc/refman/5.7/en/xa.html
See if you can switch to use MySQL Connectors setup connection to connect to MySql in SQL Server instead of OLEDB provider, which state by MySql document above that support distribute transaction.
If still not working, it might be the MSDTC service itself has some problem, see if you can isolate that like get a SQL Server instance running on the MySql server box(if you are using Windows MySql), or try install Windows MySql on the Sql Server box to get distribute transaction working between two MySql. Which would be able to point you to the actual problem.
EDIT:
Unfortunately it looks that you proved this not working, I've a closer look at the MySql document and sorry it looks that I wasn't reading it thoroughly, it says:
Currently, among the MySQL Connectors, MySQL Connector/J 5.0.0 and higher supports XA directly
And by some other Googling I found this: https://bugs.mysql.com/bug.php?id=37283, people report this bug many years ago and they marked this as a won't fix.
Some one suggested something here: https://social.msdn.microsoft.com/Forums/en-US/fc07937d-8b42-43da-8c75-3a4966ab95f9/xa-msdtc?forum=windowstransactionsprogramming, which is to implement your own XA-Compliant Resource Managers to be used by your application (https://msdn.microsoft.com/en-us/library/ms684317.aspx)
As on SQL 2014, you could have configured the linked server not to enlist in a distributed transaction. Although you could try adding "Enlist=false" in the #provstr argument to sp_addlinkedserver
Related
I'm trying to connect to a MySQL server instance, using a distributed query, with the folling query:
SELECT *
FROM openrowset('SQLNCLI11','server=<>,33333;uid=root;pwd=<>','SELECT * FROM mov.users')
I get the following errors:
OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Client unable to establish connection due to prelogin failure".
OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Protocol error in TDS stream".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "SQLNCLI11" for linked server "(null)".
I've tried using SSL on my MSSQL instances and nothing. I've ran the execute command for the sp_configure to enable 'ad hoc distributed queries', and nothing. I've tried to create a linked server but it doesn't seem to be a mssql on linux compatible feature.
How can I cestablish a direct connection between a MSSQL running on linux to a MySQL server?
On Linux, SQL Server does not support Linked Servers to data sources other than SQL Server. See unsupported features
Specs:
Sql Server 2008
Server 2008 R2 64bit
MS Access database
What works:
I have configured a Linked server connection to the Access database by installing office access data components and creating a system DSN and whatnot.
which resides in a directory on the same server.
I have succeeded in quering data through openquery.
SELECT * FROM OPENQUERY(LINKEDHELL, 'SELECT * FROM [D:\path\mordor.mdb].Orcs')
I can insert/update/delete through openquery (from inside the Sql Management Studio)
What does not work:
I have created a database which exposes a view that wraps the openquery expression. This allows my applications to remain oblivious to the fact thats its quering through an linked server connection and allows me to use an ORM. Case in point: Entity Framework.
However whilst retrieving data works, updating/inserting/delete wont.
I have spend quite some time making sure that the MSDTC is configured correctly however no dice.
What i tried
MSDTC
Enabled Network DTC Access
Allow Inbound/outbound
Configured Firewall
Enabled XA Transactions
Gave account under which DTC works access to the .mdb
Restarted Sql Server after making these settings
Other
Configured linked server security: Created mapping between sql user and local admin account, so that when i login with that sql user, it uses the local administrators account to connect to the access database.
Enable Promotion of Distributed Transactions for RPC : False
The error im getting:
OLE DB provider "MSDASQL" for linked server "LINKEDHELL" returned message "[Microsoft][ODBC Microsoft Access Driver]Invalid attribute/option identifier ".
Msg 7391, Level 16, State 2, Line 4
The operation could not be performed because OLE DB provider "MSDASQL" for linked server "LINKEDHELL" was unable to begin a distributed transaction.
I can simply recreate this by doing this from the Sql Management Studio
begin distributed transaction
//anything that queries the linked server
commit transaction
So what have I missed?
I have read that distributed transactions are supported by the ODBC driver, but im unsure if the ACCESS database does. So if someone could at the very least confirm that. That would help.
Access doesn't have transactions, because Access is not a database
engine. Jet/ACE (Access's default db engine) has supported
commit/rollback as long as I've used it (since Jet 2.x, e.g., 1996).
It has never supported transaction logging and probably never will (I
recognize that's not what you're asking about but many of those coming
to Jet/ACE from server database backgrounds are rather foggy on the
meaning of the term "transactions" and have a hard time grasping that
Jet/ACE supports one and not the other). – David-W-Fenton Jan 16 '10
at 23:12
-- Do we have transactions in MS-Access?
David W Fenton, MVP, RIP
Running MSSQL Server 2008 Standard SP 2 64-bit on Win2K8. I have installed on this server the 64-bit MySQL ODBC driver version 5.1.8 from 10/28/2010. I have configured a DSN linking to a MySQL server 5.1 running on a Mac apple-darwin9.8.0 server (don't ask me, I inherited this). I have successfully created a linked server via MDSASQL to a specific MySQL database.
From the SQL Server box I can run simple queries of the nature
SELECT * FROM mysql_table WHERE id = 1;
However, it is painfully slow. A query as above takes 19 minutes and 52 seconds to execute; the same query takes 0.04 seconds when executed locally.
Further, I attempted to execute a simple update of the nature
UPDATE mysql_table SET field = 0 WHERE id = 1;
This ran for 2 hours before returning the following error:
OLE DB provider "MSDASQL" for linked server "LINKED_MYSQL" returned message "Out of memory.".
Msg 7399, Level 16, State 1, Line 3
The OLE DB provider "MSDASQL" for linked server "LINKED_MYSQL" reported an error. The provider ran out of memory.
Msg 7330, Level 16, State 2, Line 3
Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LINKED_MYSQL".
This comes on the heels of several failed jobs involving updates to the same table, all of which fail approximately two hours after they commence.
I have checked the permissions on the mysql and the user specified in the DSN has the appropriate permissions (well, all permissions) in mysql.user.
I would be most appreciative if anyone could give me any avenues to investigate to get this working.
Avoid joins to linked server tables and have a look at dynamic openqueries
And refer to this question that posted ealier.
Linked Server Performance and options
I have a linked server in SQL Server 2008 that's using the MDASQL provider to access a Visual Fox Pro ODBC DSN.
I'm receiving the below errors when attempting to perform simple queries:
OLE DB provider "MSDASQL" for linked server "odbclinkedserver" returned message "[Microsoft][ODBC Visual FoxPro Driver]Not enough memory for file map.".
Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "MSDASQL" for linked server "odbclinkedserver" reported an error. The provider ran out of memory.
Msg 7306, Level 16, State 2, Line 1 Cannot open the table "odbctable" from OLE DB provider "MSDASQL" for linked server "odbclinkedserver".
I'm trying to run this update query that is the goal of the activity:
update odbclinkedserver...odbctable
set memofield = m1.blob
from sqlsvrtable m1
where m1.int_1 = odbctable.int_1
and m1.int_2 = odbctable.int_2
and m1.time= odbctable.time
and odbctable.date= '2011-06-28'
I have also attempted some simpler queries and still receive the same errors:
select top 1 * from odbclinkedserver...odbctable
The DSN source is a Free Table directory. The sizes of the files involved are:
odbctable.dbf = 62MB
odbctable.cdx = 9.85MB
odbctable.fpt = 200MB
I have configured the SQL instance to start with the '-g' parameter with a value of 1024 so that a gig of memory is set aside for this operation (this is a test server with no other activities).
Reference used: http://msdn.microsoft.com/en-us/library/ms190737.aspx
Given the size of the files involved, the simplicity of the queries, and that I've set aside a gig of RAM for it to use, I am running out of ideas of how to resolve this problem.
Can anyone suggest a solution to resolve these errors so that I can update the target dbf with the update query above?
Whilst you seem to have enough memory set aside when I had the same issue a stop and start of the SQL Server service followed by running sp_dropserver and sp_addlinkedserver was enough to resolve the issue:
IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0 AND srv.name = N'DBF_XXX')EXEC master.dbo.sp_dropserver #server=N'DBF_XXX', #droplogins='droplogins'
GO
EXEC master.dbo.sp_addlinkedserver #server = N'DBF_XXX', #srvproduct=N'Microsoft Jet', #provider=N'VFPOLEDB', #datasrc=N'D:\Data To Import\XXX\data', #provstr=N'dBASE 5.0'
--For security reasons the linked server remote logins password is changed with ########
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'DBF_XXX',#useself=N'False',#locallogin=NULL,#rmtuser=N'Admin',#rmtpassword='########'
Make sure you're not violating any of VFP's ODBC restrictions in either the environment or the table structures. Especially note that ODBC hasn't been suported for some time. Check here for a good list of restrictions. Is using the OLEDB driver a possibility for you? If so do a web search for "VFPOLEDB driver download" to get what you need.
Are there any free solutions for automatically migrating a database from MySQL to SQL Server Server that "just works"?
I've been attempting this simple (at least I thought so) task all day now. I've tried:
SQL Server Management Studio's Import Data feature
Create an empty database
Tasks -> Import Data...
.NET Framework Data Provider for Odbc
Valid DSN (verified it connects)
Copy data from one or more tables or views
Check 1 VERY simple table
Click Preview
Get Error:
The preview data could not be
retrieved. ADDITIONAL INFORMATION:
ERROR [42000] [MySQL][ODBC 5.1
Driver][mysqld-5.1.45-community]You
have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near
'"table_name"' at line 1 (myodbc5.dll)
A similar error occurs if I go through the rest of the wizard and perform the operation. The failed step is "Setting Source Connection" the error refers to retrieving column information and then lists the above error. It can retrieve column information just fine when I modify column mappings so I really don't know what the issue is.
I've also tried getting various MySql tools to output ddl statements that SQL Server understand but haven't succeeded.
I've tried with MySQL v5.1.11 to SQL Server 2005 and with MySQL v5.1.45 to SQL Server 2008 (with ODBC drivers 3.51.27.00 and 5.01.06.00 respectively)
There are two free toolkits provided by Microsoft.
Microsoft SQL Server Migration Assistant for MySQL v1.0
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14280
Microsoft SQL Server Migration Assistant for MySQL v5.1
http://www.microsoft.com/download/en/details.aspx?id=26712
I have used only the second one and it worked for me without any glitch.
It required registration with Microsoft for downloading a license file.
But it is free to use for everyone.
This is really old now, but if you use MySQL Connector NET and set SQL Server Mode = true in the connection string, this will resolve your error.
Recently, I have successfully migrated the MySQL database to MSSQL database. Below are detailed steps:
Operating System: AWS Microsoft Windows Server 2012 R2 with SQL Server Standard
Tools Used:
SQL Server 2014 Management Studio SQL Developer,
Microsoft SQL Server Migration Assistant v6.0.1 for MySQL,
Remote Desktop Client, and
Third Party MySql ODBC Driver 5.1.13
1. Setup AWS Windows Server
2. From the AWS console ec2 instance list, right click on the windows server and select connect. You would see the similar screen below.
3. Click on the Get Password button which will be required for Remote Desktop connection[#4] and follow the instructions.
4. Connect to that EC2[#1] instance with the Remote Desktop Client by default available in your Ubuntu local machine. Use the credentials from #2.
5. Once you get connected using the remote client, you should be able to access the remote MSSQL server. Install the following tools.
Install Chrome : Since internet explorer has some security, install chrome.
Install Microsoft SQL Server Migration Assistant v6.0.1 for MySQL
https://www.microsoft.com/en-us/download/details.aspx?id=51218
Install Third Party MySql ODBC Driver 5.1.13
https://dev.mysql.com/downloads/connector/odbc/5.1.html
6. Configure ODBC Data Sources(64-bit) :
Open Administrative tools → click on ODBC Data Sources(64-bit) and
follow the steps to connect to MySQL database.
7. Open SQL Server 2014 Management Studio SQL Developer and connect using windows authentication.
Create destination MSSql database for MySql migration.
8. Open Microsoft SQL Server Migration Assistant : For detail visit this link: https://blogs.msdn.microsoft.com/ssma/2011/02/07/mysql-to-sql-server-migration-how-to-use-ssma/
Create new project
Connect to MySql
Connect to MSSql
Convert Schema
Migrate Data
8. You might have some problem listed here. Please read in detail where I have written the detail resolution.
MySql 5.6 to MSSql server 2014 migration : ExecuteReader requires an open and available Connection
I am afraid there is no simple solution. SQL used in MySQL and T-SQL used in SQL Server 200X are different dialects of SQL. It is not only simple changing say "auto_increment" to "identity", but reserved words that creates a problem.
For example
CREATE TABLE test (
user varchar(50)
)
will work in MySQL and fail in SQL Server 2008.
To cut long story short - unfortunately, you will need to do it by hand.
Export the file from MySQL to a CSV file.
Export the create statements for the tables from MySQL
Cry.
3a. Disable foreign key checks in SQL server
Tune the create statements in SQLserver until they work.
Import the CSV files in to MySQL.
5a. Enable foreign key checks in SQL server.
Also see these answers:
migrate-from-mysql-to-sql-server-2008
Had similiar issue about this error 42000, and for me I figured out that setting the MySQL global mode to ansi_quotes would solve it:
set global sql_mode=ansi_quotes;
There are commercial solutions, but not free solutions. Depending on complexity of your database, rewriting SQL for target dialect can be trivial task - or a very hard one.
Rewriting CREATE TABLE statements is never hard, it can be done by hand with no surprises. Procedures, functions and triggers are problematic.