SQL server scheduled tasks send Excel files best way? - sql-server

I'm looking for advice for the following 'issue'.
I need to send Excel files (not CSV) to our customers with SQL SERVER.
After intense searching, I've found out that the .XLSX extension out of SQL server isn't possible (not directly), and I should be using SSIS for this.
I've never used SSIS before, did some research, and found out that I need to create .dtsx packages and schedule them to run in SQL server.
I have up to 80 reports to be sent on a daily basis (each with individual queries, connecting to the same database); this database is a Linked server on the SQL server (Old school firebird DB).
Some of the queries result in multiple mails (e.g. "Send Mail for each record" - the record contains the receiver and it's values for the body of the mail). Others are just simple Xxcel tables.
Just to be sure that I'm on the right track here, these would be the steps:
Create one project in VS 2017 (Integration Services Project) for all the reporting
Create new Package (for each report)
Create ODBC connection to the SQL database (Data Flow => ODBC Source)
And this is where I'm stuck.
So some advice here would be great.

4) Send mail task Specify the attachment as the file you just created.
Personally, I prefer sp_send_dbmail as my method for sending email but either will work and both support attachments:
sp_send_dbmail (Transact-SQL)
A third option is to use SSRS to build the reports as a table/matrix and then define a subscription for the users

Related

How to periodically update SQL Server table from an Excel sheet

For my .NET Application I have an Excel file that is used as the data source. This Excel file is updated every hour. My current back-end database technology is MS Access. The Access file has a linked table to the mentioned Excel file. I would like to switch over my back-end to SQL Server.
My question is how can I create a linked table in SQL Server such that I always have the current data in my SQL Server database. Right now I have managed to import the Excel sheet through the import wizard in SQL Server Mgmt. Studio. But obviously this is static (not updated hourly like the excel sheet).
Can I create some sort of procedure that runs every hour, reads the Excel sheet and import to my SQL Server database? How would I go about doing that? Or any other method as long as my table in SQL Server gets updated on an hourly basis with data from the Excel sheet.
One, do not code read "in process" from the excel file. That is a disaster waiting to happen. Some user opens the file, locks it, and now your sql-server starts failing. :) That is a bad scenario.
You should create an ETL package to run (hourly)?
https://learn.microsoft.com/en-us/sql/integration-services/ssis-how-to-create-an-etl-package?view=sql-server-ver15
What is SQL Server Integration Services (SSIS)? MicrosoftSQL Server
Integration Services (SSIS) is a platform for building
high-performance data integration solutions, including extraction,
transformation, and load (ETL) packages for data warehousing. SSIS
includes graphical tools and wizards for building and debugging
packages; tasks for performing workflow functions such as FTP
operations, executing SQL statements, and sending e-mail messages;
data sources and destinations for extracting and loading data;
transformations for cleaning, aggregating, merging, and copying data;
a management database, SSISDB, for administering package execution and
storage; and application programming interfaces (APIs) for programming
the Integration Services object model.
data sources and destinations for extracting and loading data;
Deploy and Schedule:
https://www.mssqltips.com/sqlservertutorial/9069/deploy-and-schedule-an-sql-server-integration-services-ssis-package-step-by-step/
Scheduling the SSIS Package with SQL Server Agent
Manually executing packages is one thing, but normally you will schedule packages so your ETL can run in a specific time windows
(probably at night). The easiest option is SQL Server Agent. You can
right-click on the Jobs node to create a new job:

Creating a snapshot database to another SQL Server

I'm trying to save the values of several columns of one table to another table on a different server. I am using SQL Server. I would like to do this without running external programs that query from this database and insert the results into the new database. Is there any way to do this from within the SQL Server Management Studio?
This is a recurring event that occurs every hour. I have tried scheduling maintenance tasks that execute custom T-SQL scripts but I'm having trouble getting the connection to the remote server.
Any help would be appreciated.
If you can set up the remote server as a linked server you should be able to configure the SQL Server Agent to execute jobs that contain queries that access tables on both the local and linked server. Remember that you might have to configure the access rights for the account used to run SQL Server Agent so that it has permissions to read/write tables on both servers.
This practice might not be without issues though as this article discusses.
You can use a 4 part name like;
INSERT [InstanceName].[DatabaseName].[SchemaName].[TableName]
SELECT * FROM [SourceInstanceName].[SourceDatabaseName].[SourceSchemaName].[SourceTableName]
But first you will have to set the remote server as a linked server as so;
https://msdn.microsoft.com/en-us/library/aa560998.aspx

Access as the front end and sql server as the backend

I have some Access tables with many number of fields. I have migrated each access table to 6 or 7 sql server tables. I am using sql server 2008. Now I want to use Access as the front end so that I can enter the data in access but it will be stored in sql server. I know that I have to make a ODBC connection. But I am not sure of how to create a access form to use it as a front-end. I am sorry if it's a basic question...
You will probably want to start with an empty Access database (since the table structures and any existing forms and reports will not match what you created in SQL server).
First step is to establish an ODBC connection to your SQL Server database. Then you will "link" the tables in SQL Server to your Access database.
Now, you have an Access database with all the tables that you linked from SQL Server. Those tables still "live" in SQL Server and when you edit them in Access the data will be stored in SQL Server.
You can then build Access forms and reports using these tables just as if the tables were native to Access.
The most versatile way is to use ODBC links to your SQL Server tables and views. That approach allows you the flexibility to link to other ODBC data sources, tables in other Jet/ACE database files, create Jet/ACE tables locally in your database, link to Excel spreadsheets, and so forth. You can incorporate a broad range of data sources.
If you choose ADP, you will be limited to OLE DB connection to a single SQL Server instance. And you will be essentially locked in to SQL Server. You would not be able to switch the application to a different client-server database without a major re-development effort.
Regarding deployment overhead with ODBC, although you may find it convenient to use a DSN during development, you should convert your ODBC links to DSN-less connections before deployment. That way your user's won't each require the DSN. See Doug Steele's page: Using DSN-Less Connections
Well you can create an ODBC connection. You can also create an ADODB connection as well. If your objective is to update or modify a SQL database, both connections will do the trick.
Now, I guess you have to get familiar with the corresponding objects. These should be tables, queries, commands, etc .., that will allow you, for example, to build recordsets out of SQL queries ... Once you are clear with that, you can, for example, assign a recordset to a form through the Set myForm.recordset = myRecordset.open ... method.

SQL Server 2005 Analysis Service (SSAS) Partial Synchronization

I'm new to SSAS (this is my first project that involves ssas).
I have a regular a SQL Server 2005 server (say Blah) that run database instance and sql server analysis service. I want to synchronize some of the data in Blah (based on some condition) to another server, Blah2. Partial data sync is quite straightforward with the help of replication server. However, I'm not sure how to do a partial data synchronization for the analysis service.
I have a table in Blah database that list all of the cubes in its analysis service. I then need to filter this table to list all the necessary cube and this is ok. But I'm sure how to continue from there.
I've looked into the SSAS Database Sync Wizard but I couldnt find any command line tools for this or a way to run this as procedure in SQL Script (I will need to do this as a regular sql server job, so it's necessary not to rely on gui). Even if I want to use the gui, there doesnt seems to be a way to filter the cube/measurement from the gui.
I'm thinking of getting the cube, measurement, data source view, etc dynamically but I cant find a way to get these definitions dynamically from sql script. I'm trying to do simple openquery to get list of cube in sql server screen with this (olap_server is a linked server to the ssas):
select *
from openquery(olap_server, 'select [CATALOG_NAME]
from $system.dbschema_catalogs')
with no luck. I got the "An error occurred while preparing the query "select [CATALOG_NAME]
from $system.dbschema_catalogs" for execution against OLE DB provider "MSOLAP" for linked server "olap_server"." error instead.
Is there any straightforward way to do this task?
I am looking at doing something similar...
You can synchronize without using the Database Sync Wizard gui by issuing an XMLA Synchronize command against the Target database as described here http://msdn.microsoft.com/en-us/library/ms187156.aspx
or for 2005 here: http://msdn.microsoft.com/en-us/library/ms187156(SQL.90).aspx
Your SQL Server job will need to have a step of type "SQL Server Analyis Services Command"
An example and some more background info is here: http://dwbijourney.blogspot.com/2008/01/ssas-database-synchronization-for.html

How do you pull data from SQL Server to Oracle?

I'm wanting to take data from a SQL Server table and populate a Oracle table. Right now, my solution is to dump the data into a Excel table, write a macro to create a sql file that I can load into Oracle. The problem with this is I want to automate this process and I'm not sure I can automate this.
Is there an easy way to automate populating a Oracle table with data from a SQL Server table?
Thanks in advance
I suppose it depends on your definition of "easy".
The most robust approach would be to either use heterogeneous connectivity in Oracle to create a database link to the SQL Server database and then pull the data from SQL Server or to create a linked server in SQL Server that connects to Oracle and then push the data from SQL Server to Oracle.
Yes. Take a look at MS SQL's SSIS which stands for SQL Server Integration Services. SSIS allows all sorts of advanced capabilities, including automated with Sql Server Jobs, for moving data between disparate data sources. In your case, connecting to Oracle can be achieved a variety of ways.
There are three ways to automate this:
1) You can do as Paul suggested and created an SSIS package that will do this and it can be scheduled via SQL Agent,
2) If you don't want to deal with SSIS, you can download the free SQL# (SQLsharp) CLR Library from http://www.SQLsharp.com/ and use the DB_BulkCopy Stored Procedure to do this in a T-SQL Stored Proc which can also be scheduled via SQL Agent. [note: I am the author of SQL#]
3) You can also set up a Linked Server from SQL Server to Oracle, but this has the draw-back of being a potential security hole. Of course, you could use an Oracle Login that only has write-access to that single table (or something similar to that).
There are lots and lots of ways to do it. Which you choose depends on your requirements.
Using Excel is fine if it's a one time thing.
If it's a once-in-a-while thing, then you could write a simple .NET app that uses a single DataSet and multiple DataAdapters to do the data dump. C# code example here.
if it's a regular thing, then you could put the above in a Schtasks task, or you could use SSIS. I think SSIS is an extra-cost option.
if the requirement is for "online access", then a linked database is probably appropriate.

Resources