Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

How to Import Data to SQL Server from Access Database using TSQL Script

$
0
0
I want to import the data from specific Access Database and Table to SQL Server, using SQL Script. I am trying to implement the solution as given in this link -http://www.codeproject.com/Articles/21351/Import-Data-to-SQL-Server-from-Excel-or-Access-usiHere is the code that I have tried -[code]sp_configure 'show advanced options', 1;GORECONFIGURE;GOsp_configure 'Ad Hoc Distributed Queries', 1;GORECONFIGURE;GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1GOIF NOT EXISTS (SELECT 1 FROM sys.servers WHERE name = 'MSAccessConnect')BEGIN EXEC sp_addlinkedserver 'MSAccessConnect', 'Access 97', 'Microsoft.ACE.OLEDB.12.0', 'C:\SQL Project\TestDB1001.mdb' -- put here your datasource pathENDGOSELECT * FROM OPENQUERY(MSAccessConnect, 'SELECT * FROM [Table1001]') -- put table name heregosp_configure 'Ad Hoc Distributed Queries', 0reconfigure with override GO [/code]The access database file path is - 'C:\SQL Project\TestDB1001.mdb'The Table from which I want to import the data is - [Table1001]but when I run this script, I get this error -9 The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "MSAccessConnect" reported an error. Authentication failed.I am not being able to figure out, how to make it work.Secondly I need to make 2 more changes to the code posted above.1.If some access database .mdb, has got password protection, then how to include the password in the script, so that one does not have to manually feed in the password during data import work.2. How to limit the data that is to be imported from the table [Table1001] by including a WHERE Clause, like for example - SELECT * FROM [Table1001] WHERE xdate = '2015-9-16 00:00:00.000')Thanks

Viewing all articles
Browse latest Browse all 3145

Trending Articles