How to force SQL Server 2008 express import from Excel to a specific data type? - sql

I'd like to force SQL Management Studio - Import Data - from XLS excel file to read one column as specific data type? It does a type guessing. My first N rows contain decimal data, but some later columns have also characters in there. I know I need to specify IMEX=1 in the connection string to the XLS file, but as far as I know this could be done only if I were using ADO.NET application to do it. (this forces Jet engine to honor registry setting HKML\Software\Microsoft\Jet\4.0\Engines\Excel\ImportMixedTypes which is set to Text).
It could also be done if I had developer/enterprise edition of sql server 2008, and editing DTS package to include the connection string. But I use Express edition that does not allow saving DTS packages - what are my other options? Thanks

Use the OLE DB Provier for Access Database Engine (or Jet depending on version of Excel), click the 'Properties' button to bring up the 'Data Link Properties' dialog, click the 'All' tab and in the list edit the 'Extended Properties' item to add IMEX=1.
Where to get the OLE DB provider? The version for the Access Database Engine, known as ACE, which was released as part of Access2007, can be used to open Jet 4.0 data sources including Excel spreadsheets. It can be downloaded from MSDN as 2007 Office System Driver: Data Connectivity Components. The stated supported operating systems are: Windows 7, Windows Vista, Windows Server 2008, Windows Server 2003 and Windows XP. There could be an equivalent for Access2010 but I'm out of the loop.

Add a first row having text data that you remove from the target table after importing the data.

Related

What SQL type is used in Excel

This is my first post in here,
I am new to SQL and I started learning it, I use it mainly in excel to get data from an outer Database
I first go to data then Refresh all then from the menu I choose connection properties
Then a dialogue appears and I input my code in the window called Command text from the Tab Definition
I added images to show where I input my SQL code
My question is what type of SQL do I input there ?
is it mySQL or SQLServer or what ??, so I can learn it, because some commands just don't work with me the way they are supposed to do
You can connect to any database type as long as you have the appropriate ODBC drivers. For example, here is documentation for MySQL for Excel. Quote from article "Use Microsoft Query to retrieve external data":
If the external database that you want to access is not supported by the
ODBC drivers that are installed with Microsoft Query, then you
need to obtain and install a Microsoft Office-compatible ODBC driver
from a third-party vendor, such as the manufacturer of the database.
Contact the database vendor for installation instructions.
OLAP databases do not require ODBC drivers. When you install Microsoft Query, drivers are installed for databases that were created
by using Microsoft SQL Server Analysis Services. To connect to other
OLAP databases, you need to install a data source driver and client
software.
Whichever database type you connect to, you will still be using Microsoft's SQL variant (as developed for SQL Server). As a beginner you're not going to notice too many differences right off the top. Most of the differences are related to data types, such as DATE vs DATETIME. Here is a wiki on SQL Compliance and this article on MS Access SQL will also apply to Excel Query.
You can connect to many data source including: SQL Server database, Access database, MySQL database, PostgreSQL database etc..
You can find the full list here: Link

How do you link MS Access 2016 to Visual Fox Pro dbf tables as linked tables?

I have a Visual FoxPro set of tables (.dbf extension) which I want to create linked tables to in MS Access. The forums I have checked seem to indicate that the vfpodbc.dll is no longer supported. I have installed the new OLE driver, but it does not appear as an option in the Linked table manager for selection. I can access this driver from Excel 2016.
Question:
Am I limited to using the programatic link method via VBA or is there a way to get this to work using the Linked table manager?
My OS is Windows 10.
Visual FoxPro Software is "INFUSION version 8.414"
Using the FoxPro OLEDB driver, you will have to connect programmatically. There's no way to link tables the way you can from an ODBC data source.
Microsoft Dropped it's support since MS Jet 2.6, but you can try to use Advantage Database Server OBDC driver

Connect to a PostgreSQL database through ODBC on Excel 2016

I'm having trouble using ODBC to connect from Excel 2016 to a PostgreSQL database.
I tried to follow this answer, without success, and this solution from MS, without any better results...
Has anyone ever succeeded at this? I saw that Excel 2016 had some troubles with ODBC drivers, but that was like a year ago, so I was wondering if things may be better now?
Thank you for your help.
My guess is this is a 32/64 bit thing. It's the single biggest issue we've had with setting people up on PostgreSQL within Excel/Access.
Bottom line: if your Excel instance is 32-bit (which is often the case), then you need to use the 32-bit ODBC driver. The latest Pg ODBC driver has both bundled in the same assembly, so the trick is to go into 32-bit ODBC and set up the driver that way.
From there, it should all be straight-forward:
Data Tab
From Other Data Sources
Microsoft Query
Select the Data source you just set up
And so on.
II am working on a Windows 10, 64-bit version, but turns out my Office package is 32-bit. Once I manually installed the 32-bit postgresql driver here: https://www.postgresql.org/ftp/odbc/versions/msi/, i was then able to correctly enter the Driver along the lines of these guidelines: https://www.connectionstrings.com/postgresql/
Final connection string looked like:
Driver={PostgreSQL ANSI};Server=name.text.ap-southeast-2.rds.amazonaws.com;Port=5432;Database=myDBname;
I had this as a comment before, but another commentor suggested I make this an answer: on excel 2016 for windows, don't waste your time with Data>Get Data >From Database. Instead use Data>Get Data >From Other Sources> From ODBC. To set up the ODBC: Click on the Start Menu. Select Control Panel. Select Administrative Tools and double click the Data Sources (ODBC) icon. Click on the System DSN tab. Here is a more detailed article that I pulled the ODBC set-up text from. Besides being much easier to set up, "From ODBC" comes with Office Business, or Office Home, while "From Database" only comes with Office Pro.
1.Excel 2016, x86
2.You need x86 odbc-driver
https://www.postgresql.org/ftp/odbc/versions/msi/
I used psqlodbc_13_02_0000-x86.zip
3.Create DataSource
-Control Panel
-Administration
-Open the 32 bit ODBC Administrator
-User DSN
-Add new User DSN (MyPostgreDsn), check connection
4.Connect Excel to Postgre
-Data
-From other sources
-OleDb wizard
-Other/Advanced
-Microsoft OLE DB Provider for ODBC drivers
-Connection - use connection string - Build
-Machine Data Source
-Choose created data source (MyPostgreDsn)
-Ok
-Test Connection
-Ok
-Choose tableā€¦

reading excel server-side

I need to develop a service and install it into a w2003 box to read excel files a then process its info. The process is as follows, users will upload excel files using FTP and then my service must take those files, validate and then update a SQL Server DB.
The application runs fine on my computer but on the server it asks for the libraries but when I try to install the MS office 2003 Primary Interop Assemblies, system displays "Please install Microsoft Office 2003 before installing the product".
I'd prefer to stay away of any server upgrade as we should require OKs, etc.. so, is there a simple way to just read excel files without having to install any update in the server.
any comments are welcome.
Thanks,
m0dest0.
ps. using vb.net and vs 2008.
Using Interop on the server is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Since Windows Vista MS introduced several security-related measures which prevent a Windows Service from doing "desktop-like" things... which means you would have to circumvent several security measures to get it to work (NOT recommended!).
To deal with Excel in a server-scenario there are several options (free and commercial) out there:
I can recommend Aspose.Cells and Flexcel... didn't try SpreadsheetGear but hear+read lots of good things about it...
Free options (though for the newer xlsx format only!) are for example OpenXML 2 from MS and EPPlus.
For a solution with nothing to install on any recent versions of Windows Server..... I'm not sure the exact VB.NET code, but you should easily be able to do this on any machine using the Microsoft OLEDB drivers that should be available on any recent version of windows server or can be installed from a free download off of the Microsoft website for very old versions of windows server. I'll try to pseudo code this, so you will have to adapt it for VB.NET. Note that in order to reference your fields by name, the first row of the selected area in the worksheet must contain the fieldnames in the column values. Otherwise you will simply have to use numeric values to index each returned field by column position.
Set objExcelConnection = CreateObject("ADODB.Connection")
objExcelConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
objExcelConnection.ConnectionString = "Data Source=d:\path\to\excel\file\on\your\server.xls;Extended Properties=""Excel 8.0;IMEX=1;"";"
objExcelConnection.CursorLocation = 3
objExcelConnection.Open
sSQL = "select * from [worksheetname$]"
set rsWorksheet = objExcelConnection.Execute(sSQL)
do while not rsWorksheet.Eof
sValue = rsWorksheet("FieldName")
rsWorksheet.MoveNext
loop
rsWorksheet.Close
set objExcelConnection = nothing
I use the Excel Data Reader (http://exceldatareader.codeplex.com/) when I need to process Excel files. It handles xls and xlsx files without a hitch, and I've got it running in a few applications on a server OS. It saves each sheet as a DataTable object, and each "cell" in the DataTable corresponds to the Excel cell with the same address. Depending on how you set up your SQL server link, there might not be too much conversion required to dump the contents into the DB.

Can SSMA for migrating Access databases to SQL Server 2005 be automated?

I need to migrate Access databases to SQL Server 2005. Since this needs to be done from within a setup so that a customers' installation is transparently migrated to SQL Server 2005, I wonder if it is possible to automate the SSMA toolkit from Microsoft.
Actually SSMA had command-line interface (special console executable in the SSMA installation folder). It was available at some time but I'm not sure whether it made its way to last release. You should ping SSMA support about what versions had it and what examples of its usages are available. I hope this will help you.
To my own knowledge, such an automation is not available. But it is still possible for you to generate the SQL code that creates the database (the one that will begin with the "CREATE DATABASE" sentence) and launch it through your user interface on your SQL server.
To generate this code, you can
Create the access database with the Access toolkit
Generate the corresponing "CREATE DATABASE" SQL code with (for example) SQL Server Management Studio (right-click on database, choose "script database as CREATE". EMS SQL Studio offers a very nice alternative to SQL Server Management Studio
Save the code for further use
With EMS Studio, You can even decide if this code also updates the data. But I'd prefer to automate data transfer through code: you can for example browse the tables (in the right order, depending on relationships), open recordsets (one local, one SQL), and transfer data by browsing the fields (you do not even need to name them) with code like:
(localRecordset links to local table. can be DAO or ADODB; Adjust code accordingly)
(sqlRecordset links to the SQL server. can be DAO or ADODB; Adjust code accordingly)
localRecordset.moveFirst
Do while not localRecordset.EOF
sqlRecordset.addnew
For each field in localrecordset.fields
sqlRecordset.fields(field.name).value = field.value
Next field
sqlRecordset.update
localRecordset.moveNext
Loop