Getting A transport-level error when executing OPENROWSET - sql

I'm trying to get data from a CSV file using OPENROWSET but I am encountering error:
"Msg 109, Level 20, State 0, Line 0
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.)"
I used the query below
select *
FROM OPENROWSET(
'Microsoft.ACE.OLEDB.12.0',
'Text;Database=C:\Users\Public;HDR=Yes;FORMAT=Delimited(;)',
'SELECT * FROM [file.csv]'
)
I was able to get the query once when I used SELECT * but when I ran the query with the column names it caused the error above and now the query does not work even with SELECT * anymore

Try this
Open SSMS
Expand Server Objects > Linked Servers > Providers
Double click the provider (Microsoft.Jet.OLEDB.12.0)
UNTICK the "Allow inprocess" option

I had this come up today. I recently upgraded to 64-bit Excel on my system and noticed the OPENROWSET functionality broke. I downloaded and re-installed the engine and it seems to have fixed my problem.

You must use this config for sql server
SP_CONFIGURE 'show advanced options', 1;
RECONFIGURE;
GO
SP_CONFIGURE 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
EXEC master.[sys].[sp_MSset_oledb_prop] N'Microsoft.ACE.OLEDB.12.0', N'DisallowAdHocAccess', 1
EXEC master.[sys].[sp_MSset_oledb_prop] N'Microsoft.ACE.OLEDB.16.0', N'AllowInProcess', 1

Related

Error while executing xp_readerrorlog using OPENROWSET in SQL Server - querying remote data sources

Can you please help me to fix this query?
SELECT
FROM OPENROWSET('SQLNCLI',
'Server=.;Trusted_Connection=Yes;',
'SET FMTONLY OFF;EXEC master.sys.xp_readerrorlog')
I get this error:
Msg 11519, Level 16, State 1, Procedure sys.sp_describe_first_result_set, Line 1 [Batch Start Line 12]
The metadata could not be determined because statement 'EXEC master.sys.xp_readerrorlog' invokes an extended stored procedure.
I have enabled Ad-Hoc Distributed Queries as well by using below query but getting same error.
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
You cannot use OPENROWSET for an extended stored procedure. You could create a linked server
EXEC {Your Linked Server Name}.master.sys.xp_readerrorlog;
But you say you have 120 instances. (Quite why you don't have management software for so many, is another question...) So you are better off using Powershell to do this. For example
Get-SqlErrorLog
-Since LastMonth
-ServerInstance "your","Server","Instances","Here"
You would probably want other code to filter and group the results, but you haven't shown what you want.
For example you could do something like this
Get-Content "ServerInstances.txt"
| Get-SqlErrorLog -After "2022-09-16 10:00:00"
| Where Source -eq "Backup"

Getting error when Executing sp_configure 'max server memory'

When I want to set max server memory, I am getting the bellow error message:
The configuration option 'max server memory' does not exist, or it may
be an advanced option
sql query is as follow:
exec sp_configure 'max server memory', 1024
reconfigure
The error message is pretty clear, it's telling you that's an advanced option
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'max server memory', 1024;
GO
RECONFIGURE;
GO
You may want to read Server Memory Configuration Options
The error is telling you the problem here, it's an advanced setting and you haven't enabled them. A search would have led you to the documentation: Example A. Set the max server memory option to 4 GB.
:
The following example sets the max server memory option to 4 GB. Note
that although sp_configure specifies the name of the option as max
server memory (MB), the example demonstrates omitting the (MB).
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'max server memory', 4096;
GO
RECONFIGURE;
GO
Do you really want to set the Memory to 1GB though? That's nothing for SQL Server to "play" with; you're very likely going to have performance issues.

Command to read/import .dbf files from local system into SQL Server 2016 64 bit

I am trying to import .dbf files into SQL Server 2016 64bit. For this I installed Microsoft Visual FoxPro. Below setup works for 32bit version of SQL Server but not to 64bit. I also tried changing the driver's name eg: Microsoft.Jet.OLEDB.4.0, Microsoft.ACE.OLEDB.16.0, etc. but no luck.
USE [master]
GO
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
USE [master]
GO
EXEC master.dbo.sp_MSset_oledb_prop N'VFPOLEDB', N'AllowInProcess', 1
GO
And then,
DECLARE #sql AS NVARCHAR(200),
#path AS NVARCHAR(200),
#table AS NVARCHAR(200)
SET #path = 'C:\Users\sid\Downloads\VPF\'
SET #table = 'dmfiles'
SET #sql = 'Select * from openrowset(''VFPOLEDB'','''+#path+''';'''';'''',''select * from '+#table+'.dbf'')'
EXEC sp_executesql #sql
Also tried creating a Linked server type of cmd:
SELECT *
FROM OPENROWSET ('MICROSOFT.ACE.OLEDB.12.0','dBase
5.0;HDR=YES;IMEX=2;DATABASE=\Dbf Directory\','SELECT * FROM dbf_filename.dbf')
When I either try to open Linked server, run any command, SQL Server just says executing and never shows any result nor throws error.
I tried using DBF Viewer 2000 to convert .dbf to .sql and ran them against a DB but, running above SQL (if worked fine) would be great for my automation script.
Help is much appreciated!

Error Importe Excel With OpenRowSet

I'm trying to import data from an Excel file on my disk C: but when I execute the query
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;Database=C:\Hola.xlsx', 'SELECT * FROM [Ripley$]')
I get this error
Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.ACE.OLEDB.12.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode
I tried this
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
but it does not work. Somebody could help me please?
I'm using SQL Server 2008 R2 and office 2010
The SELECT statement inside your connection string is not needed, you can remove it:
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;Database=C:\Hola.xlsx', [Ripley$]')
You may also not need the Xml portion (but I'm not sure if that would cause an error):
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=YES;Database=C:\Hola.xlsx', [Ripley$]')

error while executing excel file in sql server 2008

I have tried the following query in a SQL query
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=c:\generalholiday.xls','select * from [sheet1$]')
The following error is happened:
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)"
returned message "The Microsoft Access database engine could not find
the object 'sheet1$'. Make sure the object exists and that you spell
its name and the path name correctly. If 'sheet1$' is not a local
object, check your network connection or contact the server
administrator.". Msg 7350, Level 16, State 2, Line 1 Cannot get the
column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for
linked server "(null)".
Actually I searched lot of answered based on this queries. But I did not get reliable result for me.
What I have done so far,
I installed access database engine 64 bit, and run the following queries
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO
but still the above error is occurred. it is headache for me a full day to find this solution.
Please give me solution for this problem.
I am using SQL Server 2008 (64 bit) and MS Office 32 bit
I remember having similar errors setting this up initially on my server and I can't remember which bit solved it, but I believe it may have been running the following:
USE [master]
GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1
GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1
GO
Also, if I remember correctly the Excel file can't be open elsewhere when you try to query it.