I would like to use c# to select and display data from an SQL Server and a MS Access Database (accdb).
E.g.
SELECT sqlserverTable.id , sqlserverTable.data, accessTable.info
FROM sqlserverTable
INNER JOIN accessTable on accessTable.id = sqlserverTable.id
Current approach to connect to the SQL Server in c# uses:
string connectionString = "Data Source=SQLDATA;Initial Catalog=P22;
User ID=<user>;Password=<pw>";
SqlConnection cnn = new SqlConnection(connectionString);
and Access:
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=\\network\data\access.accdb";
OleDbConnection aCnn = new OleDbConnection(connectionString);
I have read I could use linked server (sp_addlinkedserver). But I do only have read access to the SQLServer. I would love to use a c# only solution.
Is there a way to run a Join from multiple data connections?
Best wishes, Hakuin
I tried OPENROWSET as suggested by @CrnaStena but only got as far as
cnn = new SqlConnection(connectionString);
cnn.Open();
SqlCommand command = new SqlCommand(" SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'D:\\access.accdb';'admin';'' , Tabelle1) As ors ");
And then trying to get around a 'Microsoft.ACE.OLEDB.12.0' not registered error. There are plenty of solutions for this recommending to install "Access Database Engine 2007/2010 in 32/64bit " and "Office Data Connectivity Components". But so far it did not resolve the error message. Also to compile in x86 mode only. So currently I'm stuck here.
Based on the other comments: The dataset is rather small. Less than 10.000 rows are affected and those in most cases reduced using where statments to display < 100 rows.