简体   繁体   中英

MS-Access sees SQL server's datetime2 fields as TEXT

I'm upsizing my application from MS-Access FE and BE to MS-Access FE and SQL Server BE. I used the SSMA Access "upsizing" tool to convert all the tables from Access to SQL, then I linked the SQL tables in the Access FE using ODBC.

In my access database, some tables had DateTime columns that were converted in datetime(0) column in SQL Server. After I linked theses tables in Access, Access sees theses columns as text columns even if they are datetime2(0) columns in the SQL server BE.

This cause some problem because queries that were working with a date format are not working with the text format. Is there anyway to link the tables so that the datetime(0) field are treated as datetime values by Access?

According to TechNet , there is only limited support for the new data type, datetime2. I would go with datetime, if you can.

Similar issue: RESOLVED

I have an SQL server with a field as DATETIME2 data type and am connecting to it via ODBC as a linked table in MS Access on Win7.

When connecting from two different workstations using the same db, one had a proper Data Type of "Date/Time" and the other had a Data Type of "Short Text"

Solution: It turns out that the linked tables were established using two different DSN files, one had listed "DRIVER=SQL Server" and the other "DRIVER=SQL Server Native Client 11.0". In order to have "Date/Time" Data Type through the ODBC link, I needed to use Client 11.0.

To see what drivers you have installed:

From the start menu search for "ODBC"
Select "Data Sources (ODBC)".  
Click on the "Drivers" tab 

You will see the drivers you have installed. I have three.

SQL Server                     6.01.7601.17514
SQL Server Native Client 10.0  2007.100.5500.00
SQL Server Native Client 11.0  2011.110.6020.00

I believe SQL Server version 6 is installed by Win7 and updated via Windows Update. If this is all you have, you will only get TEXT out of DATETIME2 SQL DataTypes through linked tables.

The Native Clients were installed by SQL Server Management Studio 2008 and 2012 respectively.

You can download and install SQL Server Native Client 11.0 from https://www.microsoft.com/en-us/download/details.aspx?id=36434

I ran into the same issue which is what led me to this page, but I figured out the solution: Problem: linked tables from access to sql server show datetime2 columns as text, which has many implications like date comparison, sort, etc,.

Solution: convert datetime2 in sql server to date time, and access will show the column as date field right away

Note that since tables already have data, you can't just change data types, I plan to add new columns datetime type, copy data over, remove orig column, rename

How to check accuracy: I created a table with 3 columns in sql server, datetime, datetime2, date then I linked to it from access, only datetime showed as date field in access, other 2 showed as text

The SSMA for Access will convert any date/time field with values that are invalid in SQL Server to text. You should run the SSMA to try the conversion and it will tell you the problems, and then you can clean up the data before your actual conversion.

You'll have to skip the SSMA wizard, as it does the upsizing without previewing the results.

It is generally required to verify your dates BEFORE the upsizing wizard. Users tend to enter "stupid" dates that are accepted by Access date fields but cause error in SQL Server. Try querying your tables with for dates outside a reasonable range like "BETWEEN 1/1/1930 and 1/1/2020" and correct those dates before restarting the upsizing wizard.
I have also found a product which I haven't used but which looks good: http://www.upsizing.co.uk/features_translate.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM