Exporting data from SQL Server to Excel - sql-server

i;m trying to automate the exporting of data from an sql server table to an excel using this script
EXEC sp_makewebtask
#outputfile = 'C:\testing.xls',
#query = 'Select * from HCIndonesia_20Jul2010..Combine_Final',
#colheaders =1,
#FixedFont=0,#lastupdated=0,#resultstitle='Testing details'
but i;m getting an error:
Msg 15281, Level 16, State 1, Procedure xp_makewebtask, Line 1
SQL Server blocked access to procedure 'sys.xp_makewebtask' of component 'Web Assistant Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Web Assistant Procedures' by using sp_configure. For more information about enabling 'Web Assistant Procedures', see "Surface Area Configuration" in SQL Server Books Online.

This blog article might help you.
It sounds like you simply need to do:
sp_configure 'Web Assistant Procedures', 1
RECONFIGURE
And your script should work (as long as you have permissions on the SQL server)

Related

Get data from Microsoft Azure using SQL Server without using linked server

I have data stored in Microsoft Azure and want to retrieve and store into Microsoft sql server 2008 r2
without creating linked server.
Try:
Step 1: Configured Firewall settings in Azure by adding Client IP.
Step 2: Running following query from SQL Server:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
SELECT *
FROM OPENROWSET('MSDASQL', 'Driver={SQL SERVER}; Server=server.database.windows.net;Database=DBName;UID=Admin; PWD=********;', 'select * from tablename')
Note: The above steps works fine but after sometime getting following error:
Cannot initialize the data source object of OLE DB provider "MSDASQL"
for linked server "(null)".
The "SQL Server" ODBC driver that ships with Windows is deprecated and cannot be used with Azure SQL Database. It's generally best to use OLE DB with linked servers instead of ODBC when possible.
Below is and example using a SQL Server Native Client OLE DB driver:
SELECT *
FROM OPENROWSET('SQLNCLI', 'Server=server.database.windows.net;Database=DBName;UID=Admin;PWD=********, 'select * from tablename;')

AzureSQL- Could not find stored procedure 'sp_configure' while installing Sitecore9.1

I am installing Sitecore9.1 with powershell using Azure SQL server and databases. While running script, it creates databases and while creating/updating MarketingAutomation databases it is giving error about 'contained database authentication'
error is - The command started with the following:
"exec sp_configure 'contained database authenticati"
Could not find stored procedure 'sp_configure'.
Install-SitecoreConfiguration : Command C:\Program Files\iis\Microsoft Web Deploy V3\msdeploy.exe returned a non-zero exit code - (-1)
I am running below command to Azure SQL server for this issue:
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
but while executing it throws error about syntax.
I could not find commands for AzureSQL or SQL2017 for contained database authentication.
I want commands for contained database authentication for Azure SQL.Please help.
sp_configure is not available on Azure SQL Database and you should use ALTER DATABASE SCOPED CONFIGURATION instead to configure Azure SQL Database options and parameters.
The following query should tell which databases have contained database authentication enabled.
select [name] as databasename, containment, containment_desc from sys.databases
As you can read on this documentation, the containment value of zero applies to Azure SQL Database, but value1 cannot be set on Azure SQL Database. However you can create contained database users on Azure SQL Database without the need to enable containment, and the contained database user model is the recommended model instead of the traditional connection model as mentioned here.

Import data from XLS file to SQL Server 2008 R2 database

Here's our situation:
We have:
SI = 64bit Windows Server 2008 R2 Standard
DB = SQL Server 2008 R2
NO Microsoft Office package are installed on this server (we can't open .xls, .ppt, .doc etc)
We tried to import an Excel 97-2003 file using the wizard and everything worked!
The problem is: we need to execute a query with some control in it that imports data from the Excel file into our database.
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\file.xls', 'SELECT * FROM [Clienti$]')
but we get the following error:
Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
We already configured some options following this guide
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
Unfortunatly according to this thread:
Microsoft.Jet.OLEDB.4.0 is not supported for 64-bit OS.
Additionally this link may be helpful to work through.
Try change 'Microsoft.Jet.OLEDB.4.0' to 'Microsoft.ACE.OLEDB.12.0'?

Export SQL QueryResult to Excell file on Server without installing Office

I want write result rows of a query to a excell file:
INSERT into OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\temp\testing.xlsx;',
'SELECT Id,CompanyName FROM [Sheet1$]')
select Id,CompanyName from tbl_Company
But When Running This query following error occurs :
Msg 7302, Level 16, State 1, Line 3
Cannot create an instance of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
What is done before running this code :
1 - I installed "2007 Office System Driver: Data Connectivity Components"
2 - Executed Configuration Script for using excell :
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
3 - Change Login Account for SQL Server Service to local account
4 - Added Full Access permission on Excell file folder to local account
5 - Restarted SQL Service
But my problem remains
Server : Windows Server 2008
MS Office not installed on server
SQL Server 2014 64bit SP1
I had a mistake :
I should run this configuration script
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 you should be sure to install 64bit version of Access Database Engine (if your sql server is 64bit).

SQL Server 2012 querying Access 2007 data using OPENROWSET error

I would like to query data in Management Studio from a Microsoft Access 2007 database located on the same machine as my SQL Server 2012 instance. I do NOT want to use a linked server to do this as different Access databases can be chosen by the user. I am following the directions found on technet and other sources I have read said to use OPENROWSET as the proper way to do what I want, but when I execute this in Management Studio...
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'C:\Users\oliver.klosoff\Desktop\New folder\41000-13-0085 Consolidated Killers LLC.mdb';
'admin';'',tblTtlHrsFringes);
...I get the error below:
Msg 7302, Level 16, State 1, Line 1
Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
The database does not have a password set for the admin user, and the admin user has permissions to read this table. Access 2007 32bit is installed on the machine, which is 64 bit, as well as the SQL Server instance. I believe that SQL Server can access the database file because when I get 1 when I execute this:
DECLARE #out INT
EXEC master.dbo.xp_fileexist 'C:\Users\oliver.klosoff\Desktop\New folder\41000-13-0085 Consolidated Killers LLC.mdb', #out OUTPUT
SELECT #out`
Is there a way to do what I am trying to accomplish?
Finally, after several unsuccessful attempts to have SQL Server "talk to" an Access database – either as a "Linked Server" in SSMS or via OPENROWSET() in T-SQL – I found this blog post that offered the following three (3) suggestions.
Tweak #1: OLE DB Provider settings
The OLE DB Provider for ACE (or Jet) must have the "Dynamic parameter" and "Allow inprocess" options enabled. In SSMS, open the
Server Objects > Linked Servers >Providers
branch, right-click "Microsoft.ACE.OLEDB.12.0" (or "Microsoft.Jet.OLEDB.4.0"), choose "Properties", and ensure that those options are selected:
Tweak #2: Temp folder permissions
This is the one that was stumping me.
Apparently SQL Server needs to write information into a temporary file while running an OLE DB query against an Access database. Because SQL Server is running as a service it uses the %TEMP% folder of the account under which the service is running.
If the SQL Server service is running under the built-in "Network Service" account then the temp folder is
%SystemRoot%\ServiceProfiles\NetworkService\AppData\Local\Temp
and if it is running under the built-in "Local Service" account then the temp folder is
%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Temp
My problem was that SSMS was running under my account (not NETWORK SERVICE) so I only had Read access to the Temp folder
Once I granted myself Modify permissions on that folder
and enabled OPENROWSET queries as documented in another question here, namely ...
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
... my query worked fine:
Tweak #3: memory_to_reserve
Although I didn't need to use it in my case, the aforementioned blog also claims that adjusting the "-g memory_to_reserve" startup parameter for the SQL Server service can also help avoid similar errors. To do that:
launch SQL Server Configuration Manager
right-click the SQL Server service ("SQL Server Services" tab) and choose "Properties"
on the "Advanced" tab, prepend -g512; to the "Startup Parameters" setting
restart the SQL Server service
For more details on the "memory_to_reserve" setting see the MSDN article here.
This should work
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
USE [DatabaseName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SELECT * FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0','Data Source="C:\Employees.accdb"')...tblEMPS;
Assuming you have the 'Northwind' sample installed (and in folder mentioned below), will the following run?
SELECT CustomerID, CompanyName
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb';
'admin';'',Customers);
GO
Unfortunately I have not reinstalled SQL Server since my last reimage
Microsoft.Jet.OLEDB.4.0 may not work now(in 2018). Need to download AccessDatabaseEngine_X64.exe or AccessDatabaseEngine.exe to SQL server and intall it. Then use Microsoft.ACE.OLEDB.12.0.

Resources