I'm trying to import an XML fie into SQL Server 2000 (SP2) table. I tried below query and it's giving syntax error near the word BULK. Not entirely sure if BULK and SINGLE_BLOB work in SQL Server 2000 SP2.
SELECT * FROM OPENROWSET(BULK N'E:\temp\PersonData.xml', SINGLE_BLOB) AS x
Also tried below query....
SELECT * FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Text Driver (*.xml)};DefaultDir=E:\temp\PersonData.xml;',
'SELECT * FROM [PersonData.xml];' )
....and it gave this error:
[OLE/DB provider returned message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified]
OLE DB error trace [OLE/DB Provider 'MSDASQL' IDBInitialize::Initialize returned 0x80004005: ].
What am I doing wrong here? or Is it a SQL server 2000 issue?. My goal is to import an XML file into SQL Server using a stored procedure. Can't upgrade the server nor can I use a third party tool. Within these boundaries, please suggest me a way to achieve this. Thanks in advance.
OPENROWSET(BULK ...) was introduced in SQL Server 2005, so you can't use it.
OPENROWSET('MSDASQL', ...) is notorious for giving unhelpful error messages. See Error: "OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found ..." for a related question; this suggests that the file name should not be part of the DefaultDir parameter (so DefaultDir=E:\temp).
If all else fails, you could use BULK INSERT with bogus values for the field and row terminators to read the entire file in a single NTEXT column; you can then use sp_xml_preparedocument and OPENXML to read it.
Related
The following SQL running in SQL Server
select *
from openquery(oracle_ls,'select xmlelement("Test") from dual')
returns the error
OLE DB provider "OraOLEDB.Oracle" for linked server "oracle_ls" returned message "ROW-00004: Invalid column datatype".
How to return Oracle XML type via linked server?
OLEDB driver complains as the data type is not supported.
However when you convert the xml to string, it should work.
select * from openquery(oracle_ls,
'select xmlelement("Test").getstringval() from dual')
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!
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?
The following query is working fine in SQL Server 2008 R2
select *
from openquery(LinkedServerName, 'exec databaseName.dbo.SP_GET_INFO');
I'm trying to convert it using exec command, but no luck.
For instance:
exec ('call databaseName.dbo.SP_GET_INFO') at LinkedServerName
Always getting a syntax error with this message:
Could not execute statement on remote server 'LinkedServerName'
Thanks.
Thanks to #lad2025 for the great help.
Using the following script will work:
exec ('databaseName.dbo.SP_GET_INFO') at LinkedServerName
The first time I tested the code it did not work because of the driver I used to create the linked server.
I have used "Microsoft OLE DB Provider for ODBC Drivers". With this one I got the error:
OLE DB provider "STREAM" for linked server "(null)" returned message ...
The reason was because in the stored procedure I do a select on a nText column which has null values.
So, I changed the driver to "Microsoft OLE DB Provider for SQL Server" and the script worked fine.
Hope this helps someone else.
I am developping some code that transfers data between SQL servers. In this phase, all my work is on the same server (local, where I am the owner), but I am already trying to implement the OPENROWSET functionnalities that will be used at production time (where data will be on different servers and where I will have to build queries for the transfers). The following 3 codes are supposed to do the very same thing, but the one making use of OPENROWSET is giving me an error ... Bref, I am stuck! if anyone could help...
3 parts naming: works
USE db1
SELECT * INTO dbo.myTable FROM db2.dbo.myTable
OPENDATASOURCE: works
USE db1
SELECT * INTO dbo.myTable FROM OPENDATASOURCE
('SQLOLEDB',
'Data Source=127.0.0.1\SQLEXPRESS;Integrated Security=SSPI'
).db2.dbo.myTable
OPENROWSET: does not work
USE db1
SELECT * INTO dbo.myTable FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=(Local)',
'db2.dbo.myTable')
Where I am getting the following message:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.".
Of course I have tried to use the standard properties of my connection string (as with OPENDATASOURCE) but I was also getting the following error:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid authorization specification".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid connection string attribute".
For one thing: Your OPENROWSET statement isn't specifying the server instance.
Try
USE db1
SELECT * INTO dbo.myTable FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=127.0.0.1\SQLEXPRESS',
'db2.dbo.myTable')