sqlsql-servervisual-studiosqldatasource

Can I use different data connections together in Visual Studio?


Is it possible to use two or more data connections in Visual Studio and use them in a single query, like we can do in SQL server management Studio (while we use MySQL and MSSQL at the same time)?

E.g.

SELECT * INTO testMySQL.dbo.shoutbox
FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox')

Solution

  • If your using Microsoft SQL Server and MySQL, then you can use Microsoft SQL Server Linked Server to accomplish this. A Linked Server is a server linked via OLEDB. This linked server will allow you to connect to the MySQL database from SQL Server and run remote queries.

    Example

    SELECT * from MyLinkedServer.[Database].[Schema].TableName  T1
    INNER JOIN MYSQLSERVER.DATABASE.DBO.TABLENAME T2 ON T1.PK = T2.PK
    

    OR

    SELECT * FROM OPENQUERY([NameOfLinkedSERVER], 'SELECT * FROM TABLENAME') T1
    INNER JOIN MYSQLSERVER.DATABASE.DBO.TABLENAME T2 ON T1.PK = T2.PK