Cannot connect to MS Access file from SQL Server 2008 - sql-server

I have been trying for the past week or so to import data programmatically to a SQL Server 2008 table from a Microsoft Access .mdb file. I have been getting nothing but errors, and solving one just reveals another. I made the file into a linked server, and now when I try to query it with:
Select * from OPENQUERY(Importdata, 'Select * from [IMBPieceBC]')
I get the error:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Importdata" returned message "Cannot open database ''. It may not be a database that your application recognizes, or the file may be corrupt.".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Importdata".
I've read several suggestions to relink dlls in the registry, but I've done that, and I'm still getting the error. Is there anything else I can do to fix it, or at least figure out what is wrong?
Migrating the data to a SQL Server instance is not an option. The mdb files are generated by a third-party program, so there's nothing we can do about it.

I have a similar situation at my workplace - a third party application that maintains data in MDBs, but other applications needing access to it. How I've done it is that this 'intermediary' application has links to the SQL Server tables and the MDB tables. You could use either a query or a VBA written form event to transfer information from the MDB table(s) involved into your corresponding SQL Server tables using a INSERT INTO query, fitted with a SELECT FROM subquery providing the values being inserted.

Related

SQL Server select from linked server throw error if user has "deny view definition"

I have users with datareader permission on my sql, the problem is that i noticed that the users are doing "fishing" query a lot (they don't know what exactly should be querying to get what thy need).
This is a production SQL and we started to have deadlock because of those users.
Trying to don't break their process i applied "deny view definition to [user]" so they cannot see the list of tables, view, stored procedure, so no more "fishing"
This was a great solution, it works perfect if you connect directly to the SQL Server, you can run queries (select) but you cannot see the list of tables.
However many users are using those account to connect to our SQL using linked server, and when the run a query using the linked server they are getting error:
SELECT TOP 100 *
FROM [SERVERSQL].[DATABASE].dbo.[TABLE]
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "SERVERSQL" does not contain the table ""[DATABASE]"."dbo"."[TABLE]"". The table either does not exist or the current user does not have permissions on that table.
Using SQL Server version 2014 (v12.0.2000.8) and 2016 (v13.0.5492.2).
What is the correct way to hide tables, view, stored procedures, etc but allow select and make it work on linked server?
Thanks
Linked server from one SQL Server to Another:
Linked server name is: PLWNSAVSQL02D which is SQL Server
This sql to linked server works:
select count(*) from [PLWNSAVSQL02D].[SFI_WMS].dbo.[TCOMPANYPALLETMESSAGES];

How to add Sybase SQL Anywhere DB as linked server to MS SQL Server properly

I used the Microsoft OLE DB Provider for SQL Anywhere to create a linked server, it shows remote databases and tables, I can read data, but writing data seems to work only using OPENQUERY() and when doing the connection_authentication using EXEC ... AT ... directly in the script.
How can I have the SQL Server do the authentication automatically when opening a connection?
How can I make normal write operations work without OPENQUERY()?
Sorry for not adding detailed error messages, I will add them later maybe, when I have access to the server again... But they were not meaningful anyway, i.e. when the weird authentication was missing, it just said "could not insert" or "failed" instead of indicating any authentication issue.
How to get the real error messages that come from Sybase?
Details:
SAP Sybase SQL Anywhere 16 (OEM Authenticated Edition) <-> MS SQL Server 2014
EXEC 'SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=''Company=...''' AT linkedserver
INSERT INTO OPENQUERY(linkedserver, 'SELECT column FROM table WHERE 0=1') VALUES ('')
...that's not nice.
Even more details:
This is how I created the linked server
This is the authentication I'm talking about

Query database with period in name on a linked SQL Server

I need to query a database on a linked server, and unfortunately the database name contains a period.
This fails;
select top 10 *
FROM [LINKED_SERVER].[DATABASE_NAME.1].dbo.[TABLE_NAME]
with this error:
OLE DB error trace [Non-interface error: OLE DB provider unable to process object, since the object has no columnsProviderName='SQLOLEDB', Query="DATABASE_NAME.1"."dbo"."TABLE_NAME"'].
Msg 7357, Level 16, State 2, Line 2
Could not process object '"DATABASE_NAME.1"."dbo"."TABLE_NAME"'. The OLE DB provider 'SQLOLEDB' indicates that the object has no columns.
Connecting to the same linked server without a period in the database name works;
select top 10 *
FROM [LINKED_SERVER].[DATABASE_NAME].dbo.[TABLE_NAME]
As there are many references to the existing database name out of my control, I hope to find a solution that avoids re-naming the database permanently.
I would like to be able to create a synonym or some other alias, or find some other way to get this working.
Periods in database names accessed via linked servers are perfectly acceptable when escaped with brackets [] - the error your getting must be something else.
I can confirm this on my test rig:
One thought, your using the old SQLOLEDB provider for your linked server, have you tried using SQLNCLI10 instead?
Avoid periods in identifiers,
e.g. in SSMS
sp_help [sales.order]
will not work, even with brackets

From SQL Server how do I read from an MS Access database to UPDATE data in one or more table columns?

My SQL Server database table has a column that needs to be Updated with data from an MS Access file. How do I query the MS Access data to perform such an update?
Import Wizard seems to only handle Inserting of new data and not UPDATE existing data? Or am I misunderstanding how to use the wizard?
Sounds like you want to run that operation from the SQL Server side ... "pull" the Access data into SQL Server. If so, you can set up the Access file as a linked server within SQL Server. I've not done that, but have read cases where other people have. I copied these steps from How can I link a SQL Server database to MS Access using link tables in MS Access? at SQLServerPedia.
1) Open EM.
2) Goto the Server to which you want to add it as linked server.
3) Then goto security > Linked Servers section from console tree.
4) Right click on the Client area. Then New Linked Server.
5) Give a name and Specify Microsoft Jet 4.0 as Provider string.
6) Provide the location of the MDB file.
7) Click OK.
Alternatively, you could run the operation from the Access side, and push the data to SQL Server. If that could work for you, use Olivier's instructions to set up the ODBC-linked SQL Server table. Or you do it without creating a DSN: Using DSN-Less Connections.
Either way you link the table, the UPDATE statement you run from within Access might then be as simple as:
UPDATE
linked_table AS dest
INNER JOIN local_table AS src
ON dest.pkey_field = src.pkey_field
SET dest.access_data = src.access_data
WHERE
dest.access_data <> src.access_data
OR dest.access_data Is Null;
First set up a ODBC DSN in Windows. Open Control Panel > Administrative Tools > Data Sources (ODBC). Note that on 64 bit Windows, this might open the 64-bit-administrator. However, if you have a 32-bit Access, you need the 32-bit-administrator (%windir%\SysWOW64\odbcad32.exe).
Then you can link the SQL-Server tables to your access db. In the Link Tables dialog, choose "ODBC Databases()" as file type.
You can then query the linked SQL Server tables as if they were access tables.
See Configure Microsoft Access Linked Tables with a SQL Server Database

SQL Server queries xls file worked yesterday(I swear), now refuses to. 0.o

Hey all, the following select statement used to correctly query an Excel spreadsheet on a 64bit SQL Server 2008 R2, and now provides me with an error.
SELECT
MPNCode, Supplier, Stock , Price, Manufacturer, [Description]
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;Database=C:\inetpub\wwwroot\nCompass\Products\Import\SupplierProducts.xls;HDR=YES',
'SELECT * FROM [Sheet1$]') WHERE MPNCode IS NOT NULL
The error I get is.
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked
server "(null)" returned message
"Unspecified error".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"Microsoft.ACE.OLEDB.12.0" for linked
server "(null)".
I've tried restarting everything and googled the thing to death - somehow something has happened that is preventing this from working.
The file-path/file-name is correct because when I change the path I get a different error message.
Ad-hoc connections are enabled from the surface manager - after this I'm stumped at what the issue could be.
Any help will be very much appreciated.
Is the linked spreadsheet opened on the desktop? What happens if you create a new sheet in the same folder and try to open it instead?
I think SQL Server needs to access to TEMP folders to copy or create some files.
If the folder does not exist or ther SQL Service account does not have enough permission to access the folders, you'll get the exception.
Run Procmon.exe on the server and execute the query again. You can see what's happening and where the SQL Server wants to access.

Resources