Export Data from SQL Server 2014 to Excel - sql-server

I tried to export data from SQL Server 2014 to Excel.
I tried like this
insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0
Xml;HDR=YES;Database=D:\testing.xlsx;',
'SELECT OI_NAME,OI_ADDRESSS FROM [Sheet1$]') select OI_NAME,
OI_ADDRESSS from OI_TEMP
But I get this error
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 searched on the internet, and found this:
The SQL Server Error Message if a user have no rights for SQL Server TEMP directory OLE DB provider "Microsoft.Jet.OLEDB.4.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.Jet.OLEDB.4.0" for linked server "(null)".
But I assign permission is still does not work.
Why?

To export data from SQL to Excel, you need to follow 2 steps:
Step 1: Connect Excel to your SQL database‍ (Microsoft SQL Server, MySQL, PostgreSQL...)
Step 2: Import your SQL data into Excel
The result will be the list of tables you want to query data from your SQL database into Excel:
Step1: Connect Excel to an external data source: your SQL database
Install An ODBC
Install A Driver
Avoid A Common Error
Create a DSN
Step 2: Import your SQL data into Excel
Click Where You Want Your Pivot Table
Click Insert
Click Pivot Table
Click Use an external data source, then Choose Connection
Click on the System DSN tab
Select the DSN created in ODBC Manager
Fill the requested username and password
Avoid a Common Error
Access The Microsoft Query Dialog Box
Click on the arrow to see the list of tables in your database
Select the table you want to query data from your SQL database into Excel
Click on Return Data when you’re done with your selection
To update the export automatically, there are 2 additional steps:
Create a Pivot Table with an external SQL data source
Automate Your SQL Data Update In Excel With The GETPIVOTDATA Function
I've created a step-by-step tutorial about this whole process, from connecting Excel to SQL, up to having the whole thing automatically updated. You might find the detailed explanations and screenshots useful.

I try on a few years ago, do it that way and it was not possible, I suggest you use this form to export data to Excel from SQL -server.
Font: Microsoft Developer Network
Create an excel file, then option Data -> From other source -> From SQL Server
Select input your server, user and password, then select database and choose your table.
See this video:
Video Tutorial - SQL server to Excel
Then, you can code a macro on VBA to update automatically excel file
sub Auto_Open ()
ActiveWorkbook.RefreshAll
end sub
I hope this help to you!

Related

What is provider string when configuring Linked Server

I am configuring a linked server in SQL Server in order to send data from a SQL Server database to a MySQL database. While creating the linked server, in the fields to fill, I am asked the Provider string, unfortunately, I do not know what the Provider String is. Can somebody tell me what the Provider String is and how I can get it?
Here is a screenshot of the window where I need the Provider String
From the documentation Create Linked Servers (SQL Server Database Engine):
Provider string
Type the unique programmatic identifier (PROGID) of the OLE DB provider that corresponds to the data source. For examples of valid provider strings, see sp_addlinkedserver (Transact-SQL).
And then from that linked documentation:
[ #provstr = ] 'provider_string'
Is the OLE DB provider-specific connection string that identifies a unique data source. provider_string is nvarchar(4000), with a default of NULL. provstr is either passed to IDataInitialize or set as the DBPROP_INIT_PROVIDERSTRING property to initialize the OLE DB provider.
...
Remarks
The following table shows the ways that a linked server can be set up for data sources that can be accessed through OLE DB. A linked server can be set up more than one way for a particular data source; there can be more than one row for a data source type. This table also shows the sp_addlinkedserver parameter values to be used for setting up the linked server.
Remote OLE DB data source
OLE DB provider
product_name
provider_name
data_source
location
provider_string
catalog
SQL Server
Microsoft SQL Server Native Client OLE DB Provider
SQL Server 1 (default)
SQL Server
Microsoft SQL Server Native Client OLE DB Provider
SQLNCLI
Network name of SQL Server (for default instance)
Database name (optional)
SQL Server
Microsoft SQL Server Native Client OLE DB Provider
SQLNCLI
servername\instancename (for specific instance)
Database name (optional)
Oracle, version 8 and later
Oracle Provider for OLE DB
Any
OraOLEDB.Oracle
Alias for the Oracle database
Access/Jet
Microsoft OLE DB Provider for Jet
Any
Microsoft.Jet.OLEDB.4.0
Full path of Jet database file
ODBC data source
Microsoft OLE DB Provider for ODBC
Any
MSDASQL
System DSN of ODBC data source
ODBC data source
Microsoft OLE DB Provider for ODBC
Any
MSDASQL
ODBC connection string
File system
Microsoft OLE DB Provider for Indexing Service
Any
MSIDXS
Indexing Service catalog name
Microsoft Excel Spreadsheet
Microsoft OLE DB Provider for Jet
Any
Microsoft.Jet.OLEDB.4.0
Full path of Excel file
Excel 5.0
IBM DB2 Database
Microsoft OLE DB Provider for DB2
Any
DB2OLEDB
See Microsoft OLE DB Provider for DB2 documentation.
Catalog name of DB2
So you can choose the appropriate value of the provider from the OLEDB source you are using for your linked server.

Issue when trying to UPDATE table on LINKED SERVER

I connected my MS SQL Server database to Firebird using odbc. When I use a SELECT statement it works perfectly. The error occurs when I try to UPDATE. I get this error message:
The OLE DB provider "MSDASQL" for linked server "server_name" could not update table
The strange thing is, it can update some other tables in the same db, but not a select few.

Opening Data from Excel in SQL Server

I am trying to select some data from Excel into my SQL query.
I have the following query:
SELECT*
FROM
openrowset('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=S:\Nh\NHData.xlsx;',
'SELECT *
FROM [Pre Upgrade data$]') as t2
If I run this on my local SQL server instance, it works fine, however to get it to work, I had to follow the procedure outlined on the below link, setting the SQL server service to run as my user account.
http://www.aspsnippets.com/Articles/The-OLE-DB-provider-Microsoft.Ace.OLEDB.12.0-for-linked-server-null.aspx
Without changing the user, I would get the following error:
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
For obvious reasons I cannot change the SQL server user on my live SQL database server.
How can I get this to run?

SQL Server Express 2008 R2 Linked Server to IBM i (iSeries): queries return text as 0xD4F3F1F7F9F1F0

Just linked SQL Server 2008 R2 Express to iSeries and can't see my files. I can query them though. Text returned as 0xD4F3F1F7F9F1F0 instead of something like M123450 (that's a work order number). Using the IDM DB2 for IBMDA400 OLE DB Provider.
I tried using a connection string that works for other applications. I get errors:
TITLE: Microsoft SQL Server Management Studio
The linked server has been created but failed a connection test. Do
you want to keep the linked server?
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
Cannot initialize the data source object of OLE DB provider "IBMDA400"
for linked server "S10A7F0P". (Microsoft SQL Server, Error: 7303)
Has anyone encountered anything like this? I'm reasonably new to the whole SQL server thing.
Thanks in advance!
M
The reason your data is returned as 0xD4F3F1F7F9F1F0 is that the text column was defined as CCSID 65535; which stands for binary data and so by default the DB doesn't translate it from EBCDIC to ASCII/Unicode.
You can see the CCSID of the various columns in a table by using the green screen DSPFFD command or the iNav GUI.
The best way to fix this it to ensure your text columns are tagged with the appropriate CCSID for your language (37 if US).
The alternative is to force the DB to translate text columns by using the "Force Translate" property of the OLEDB driver.

OpenDataSource fails

I'm trying to export records from SQL Server 2008 to mdb file using OpenDataSource. It works when I log in using Windows authentication. But it fails when I use SQL Server authentication.
This is the error I get
OLE DB provider
"Microsoft.Jet.OLEDB.4.0" for linked
server "(null)" returned message
"Could not delete from specified
tables.". Msg 7320, Level 16, State 2,
Procedure EXPORT_Employee, Line 110
Cannot execute the query "DELETE FROM
employee_export " against OLE DB
provider "Microsoft.Jet.OLEDB.4.0" for
linked server "(null)".
A bit speculative but maybe you need to grant the SQL Server Service Account Write Access to the mdb file and make sure that you don't have it open at the same time.
Edit: A different type of permissions error anyway I think http://blogs.msdn.com/spike/archive/2008/07/23/ole-db-provider-microsoft-jet-oledb-4-0-for-linked-server-null-returned-message-unspecified-error.aspx

Resources