How reset existing sql server connection in excel workbook - sql-server

I have created an Excel workbook with SQL server connection and loaded data using SQL commands. I want to use the same excel file in a different machine, there I want to change the database credentials. In our excel file, there are more than 10 SQL server connections and sheets, So recreate the file is very difficult. Is there any way to reuse the file with a different database?
I have copied the excel file with all .odc files, But I couldn't find an option to reset the connection to the new database.

I see two possibilities:
Edit the ODC files manually with a text editor
In Excel, use "Data" -> "Connections" to edit the connections

Related

SSIS Export 1 table to multiple Excel sheets

I want to export a large table from SQL Server to excel using SSIS. I have a col called Num that I want all the same values into the same excel sheet e.g. all the 1s in 1 sheet etc. How to do this with SSIS? Do I write a SQL command text?
Num
--
1
1
2
2
2
3
4
4
Export data from SQL Server to Excel and Excel file via using SSIS package :
Configure ADO.NET connection :
To create a “Source” connection, right click “Connection Managers” and select “New ADO.NET Connection”.
a. Server Name – is the hostname or IP address of the database server where SQL is installed.
b. Authentication – is an “authentication type” used to connect Server that is selected on “Server Name” drop-down box. It can be either SQL Authentication or Windows Authentication.
c. Database Name – is the name of the database which we are going to use for data extracting.
Configure ADO.NET Source :
To populate data from SQL Server table, you must configure ADO.Net source component.
Double-click on “Data flow task” to do that. The window “Configure Data flow task” will open. Alternatively, you can select “Data Flow” that is located next to “Control Flow”. As we already configured SQL connection, we will drag and drop ADO.NET Source to data flow window.
Then select “SQL Command”, it will open a multi-line text box where we can write the Ad-Hoc query to extract data from the database.
Configure excel destination
Once we configure ADO.NET source, we will configure Excel destination.
In SSIS tool-box, drag and drop excel destination in the data-flow window and rename it as “Sales Excel File”.
a. Excel connection manager – used to connect the excel file.
b. Data access method. Excel worksheet is considered as a table or view. If you select “Table or View”, drop down box “Name of excel sheet” will be filled with all worksheets that are created in the excel workbook.
c. Name of excel sheet. By default, this drop-down box is disabled. It will be enabled automatically when we select “Table or View” as data access mode. We also can select appropriate excel worksheet.
Then, choose :
a. Excel File Path – the location of the excel file.
b. Excel version – can select excel version from drop down box.
In order to export data from SQL table to excel file, you must map the fields of SQL table and Excel file.
To do that, drag blue arrow beneath the ADO.NET component and drop it on Excel Destination component.
Double click on “Excel destination” to map the fields. “Excel destination editor” will open. Select “Mappings” option from the left pane of the dialog box. In mapping, input columns will be the columns of SQL Query output and destination columns will be the columns of the excel file. It is suggested to keep the same name of SQL Query output and excel columns. This will make mapping much easier because we do not need to map fields manually. SSIS will map columns automatically.

How to Import/load password protected excel work book to tables using SSIS?

I have an excel file and I have to load the excel data into SQL tables through an SSIS package.
I have tried creating a package and added excel connection manager and excel source but the excel is showing up an error and name of the excel sheet in the drop down is not loading...
Please help. Let me know if you need any further information. Thanks!
Apparently it is not possible to connect to a pw protected excel file even though there is that property:
https://msdn.microsoft.com/en-us/library/ms139836.aspx
I did find a workaround though using powershell to open and save as...
http://www.sqlservercentral.com/Forums/Topic885800-148-1.aspx

Create and write in text file with SSIS

I am totally new to the SSIS. I have a requirement to create a text file on specified location and write the data in it which is selected from SQL table.
How to do that?
Is there any example which will help me?
The below steps should help you to get a basic SSIS package working:
Create new Integration Services Project in Business Intelligence Development Studio. There should be a default SSIS package in it called Package.dtsx. Open the package.
In the bottom of the screen, there should be an area for connection managers. Right click on it to get a list of different connection managers.
Click on New OLEDB Connection. This will be the connection manager for your source database. Set the data source (server or instance name), authentication mode and credentials and the initial catalog (database name).
Again right click in the connection managers area and select New Flat File Connection.This will be the connection manager for the destination flat file. You can create a text file (.txt or .csv) and add in the headers for your data e.g. EmployeeID,EmployeeName,EmployeeSalary. Check the "column names in the first data row" checkbox to make sure your headers are identified as such.
Now select a Data Flow Task and drag it to the Control Flow screen.
Open the Data Flow tab. Drag 2 items from Toolbox to the screen - OLEDB Source and Flat File Destination.
In the Source, use the OLEDB connection manager created earlier. Then change the Data Access mode to SQL command. Now you can type your own command to select data. Make sure that the header data in your flat file is the same as the column headers from your select query.
In the Destination, use the Flat File connection manager created earlier. Go to the Mappings section and map the columns from your query output to the headers in your text file.
Now save and run the package. You should see that the destination text file is populated with data from your query.

How to dump SQL Server data into csv

I'm converting web application written in ASP into PHP that will be using MySQL. I have a SQL Server database with two files (.MDF and .LDF) I want to convert into CSV file but I am having trouble finding the right tool to do the job. I found that some people are suggesting SQL Server Express. I tried it but couldn't figure out how to load database from file and use it. I also tried to use opendbcopy but when trying to open a file it doesn't show it in the file pane.
If you install SQL Server Express, you can load the image file using the Attach Database functionality in the SQL Server Management Studio (the management UI).
Then you can view and work with the database directly from Management Studio, where you can export the file to CSV by right-clicking the database name and selecting Tasks->Export Data.
There's an online service called RebaseData that can do the job. You just need to upload your .MDF file and it gets converted to a .ZIP archive. The .ZIP archive will contain several .CSV files, one for each table of the database.
Link to the converter
Disclaimer: I'm working for that service.
connect database to visual studio and write query to display all data from the table you want and then right click and select all and again right click and save it .
Its done !

How to execute folder with SQL Server 2008 scripts

I have a folder with a .sql files; 1 file per query. I want to execute all queries/ sql files and save them as csv.
Is there a way to do that automated without using the windows cli (disabled in my environment). I do have the SQL Server Management Studio.
I would approach this task using SSIS, providing you have Business Intelligence Development Studio (BIDS) installed.
First create a 'Foreach Loop Container' pointed to the folder with the SQL files, then use a variable to retreive each file name.
Next, create a flat file connection and set the 'Connection String' property to the variable that contains the file location.
Next, using the 'Execute SQL Task' component set the 'SQLSourceType' to 'File Connection' and the 'FileConnection' to the one created in the previous step.
Finally, depending on how the data is returned you have a couple of options, if the result set is small, only a row or a single column, then you can save the results to a variable and using a 'Dataflow' task create a 'Derived Column' component and export the contents of that variable to a CSV file. Or, if the dataset is larger you could dump the results to a temp table and then using an 'OLE DB Source' and 'OLE DB Destination' you could push the full result set straight into a CSV.
Hopefully this isn't too convoluted of a solution, this approach has the advantage of being able be run from either a remote machine or from the server itself, plus you can automate its execution with a SQL Agent Job.
Create a VB.NET console application.
Generate a list of files that end in .SQL from the folder in question.
Load the contents of each file into individual SQL Commands
Execute the SQL Command for each, storing the results in DataSets.
For each table in each dataset, create a new .csv file
For each .csv file, you will need to iterate over each cell in the datatable, and utilize proper escaping for .csv files.
Use 'for' in combination with either sqlcmd or bcp command for each file in the script folder.

Resources