In my SSIS package I read column type datetimeoffset(7) and write to column datetime2(7) (data flow task). Select in Source returns value i.e. '2015-01-01 00:00:00.0000000 +00:00' but in destination I got '2014-12-31 19:00:00.0000000'. This 5 hours difference is related to timezone on server which hosts sql service (both database and ssis package).
Any idea what is cause of this datetime change?
The problem appears to pertain to setting a datetime in the destination that hasn't happened yet on the server in the later timezone.
The following article should address your issue with several options for resolving:
http://www.mssqltips.com/sqlservertip/3173/handle-conversion-between-time-zones-in-sql-server--part-1/
Related
Is there any way to change SQL server datetime? GETDATE() and CURRENT_TIMESTAMP show the wrong dates.
I read that SQL reads the date from the server settings where the SQL instance is installed. But on this server(Windows SERVER 2019) time, date and timezone are correct.
Only in SQL Server are those settings wrong. I've tried to find a solution for this issue over internet but I couldn't find any.
Only SYSUTCDATETIME() shows correct information.
GETDATE() and CURRENT_TIMESTAMP will be working correctly. They return the server's local time. If the time is "wrong" then it's because the time on the server is "wrong"; most likely because it thinks it's in a different timezone to where it physically is or has the wrong DST setting.
Clearly, however, the time is correct on the server for its location (in the sense of that if it's observing CET it would display 11:38 around now) as you state that SYSUTCDATETIME() returns the correct UTC time.
if the server does have the wrong time setting, however, the fix is fix the time on the server. Speak to your server administrator about that. YOu change change the values GETDATE() and CURRENT_TIMESTAMP return as they are based on the host's time. This is why I am confident the time is correct, likely it is either set to the wrong timezone or DST setting as the UTC time is correct.
If, however, the time is correct for where the server is physically located, then the answer is don't use GETDATE() or CURRENT_TIMESTAMP to get the value for your local time, instead (like you have) use SYSUTCDATETIME() or SYSDATETIMEOFFSET() and then convert the time to your timezone in the application layer.
It seems the server timezone was changed since the SQL Server instance was started. Run the query below to verify the timezone SQL Server is currently using:
SELECT CURRENT_TIMEZONE();
If the result is different than the OS configuration, restart the SQL Server instance for the new timezone to become effective.
Earlier my client was using SSRS 2008R2 with Oracle as transaction database. Recently they have upgraded to SSRS 2017 and now many reports are throwing following error:
ERROR: Throwing
Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException:
[AbnormalTermination:ReportProcessing],
Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException:
An error has occurred during report processing. --->
Microsoft.ReportingServices.ReportProcessing.ReportProcessingException:
Query execution failed for dataset 'Ds_Main'. --->
Oracle.ManagedDataAccess.Client.OracleException: ORA-01830: date
format picture ends before converting entire input string
After closely looking into report query, I have noticed that this error is for all those reports where oracle function TO_DATE(<Date Value>) has been used without date format. For example:
To_date(:Date_Parameter) -> this syntax throws above mentioned error
To_Date(:Date_Parameter,’MM/DD/YYYY’) -> this syntax works perfectly
I am willing to know:
what has changed in SSRS 2017 vs SSRS 2008 R2 that is causing this issue because same reports are working as expected in SSRS 2008 R2 and it is throwing above error in SSRS 2017.
Is there is any suggestions to fix this issue without updating bunch of reports?
what has changed in SSRS2017 vs SSRS2008R2
SSRS 2008 used the old System.Data.OracleClient. In SSRS 2016 and later you have to install the Oracle ODP.NET provider, built and supported by Oracle. So probably just a difference in how the NLS_DATE_FORMAT session parameter is set by the two drivers.
You can see your setting if you add a dataset to your report with this query:
select parameter, value
from nls_session_parameters
where parameter like 'NLS%'
order by parameter
Unfortunately there doesn't appear to be a way to globally change the client date format in Oracle.ManagedDataAccess, so you'll have to make all the changes in the report dataset queries.
Alternatively you can try to ensure that you are passing Date parameters and not string parameters. If you pass a date to Oracle's to_date() function, you don't need to specify a format.
The docs for SSRS 2014
"This built-in data source type is based on the .NET Framework Managed Provider for Oracle and requires an Oracle client software component."
And for SSRS 2016 "This built-in data source type uses the Oracle Data Provider directly and requires an Oracle client software component."
Trying to figure out the issue
I don't think the issue is related to the Visual Studio upgrade. It is related to the date format passed as a parameter to TO_DATE() function.
Based on the official documentation of the Oracle / PLSQL: ORA-01830 Error Message:
Cause: You tried to enter a date value, but the date entered did not match the date format.
In Oracle, the default date format is generally DD-MON-YYYY. If you try to enter a date value that does not comply with this format.
You seem to have passed the date parameters in the dd-MMM-yyyy format and now they are passed as MM/dd/yyyy.
First of all, check that the regional setting or the applications Culture information didn't change.
Possible workarounds
You can fix the issue using several approaches:
(1) Handling the parameters date format
If you do not want to edit all code, then it is easier to force the parameter data string format, make sure that all parameters passed to TO_DATE() function are in following format (or try to change the default date format from the OS regional settings):
dd-MMM-yyyy example: 01-AUG-2019
(2) Adding the date format to TO_DATE function
If you are sure that the date parameters format is fixed and will not change then you can edit your code as you mentioned in the question:
To_Date(:Date_Parameter,’MM/DD/YYYY’)
(3) Pass the date and format as parameters
This also requires changing the code, but you will pass the date and format as parameters.
To_Date(:Date_Parameter,:DateFormat_Parameter)
SQLFiddle demo for parsing dates
You may find other methods at the following link:
ORA-01830: date format picture ends before converting entire input string / Select sum where date query
Update 1 - Making common change in multiple reports
While searching I found the following link providing a method to loop over reports and make changes. You have to only replace To_Date(:Date_Parameter) with To_Date(:Date_Parameter,’MM/DD/YYYY’):
SSRS - Make common change in multiple reports in one click
Update 2 - Other possible workarounds
Forcing Culture info by editing ReportViewer.aspx
You can edit the ReportViewer.aspx file is located in the SQL Server reporting services directory, and force the culture info used within reports. Check out the following question it will give you more details:
I want Datetime Parameter in DDMMYYYY Format in ssrs report
Changing the browser language settings
Check the following link (read Mike Honey and Nick St Mags answers):
SSRS Datetime Parameter value should display in DD/MM/YYYY format
Update 3 - Issue cause
In addition of what #DavidBrownie posted i found the SQL Server 2008 R2 documentation:
Oracle Connection Type (SSRS 2008 R2)
Where they mentioned:
This built-in data source type is based on the .NET Framework Managed Provider for Oracle and requires an Oracle client software component.
Also if you take a look at SQL Server 2017 documentation:
Oracle Connection Type (SSRS 2017)
This built-in data source type uses the Oracle Data Provider directly and requires an Oracle client software component.
In addition, referring to Microsoft OLE DB Provider for Oracle documentation (which is the old used provider). They mentioned that:
This feature will be removed in a future version of Windows. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Instead, use Oracle's OLE DB provider.
Which is the reason for changing the provider used to connect to Oracle in Reporting Services.
I have a simple query:
select df_id
from diasferiados
where df_dia = '17/9/2017 5:20:03 PM'
I run it on PC #1 and works fine.
But when I try to run it on PC #2, I get this message:
ERROR [22007] [Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion failed when converting date and/or time from character string.
If I modify the date as follows (swap day and month):
'9/17/2017 5:20:03 PM'
It works fine on PC #2.
I can't modify my application so it must remain as the first case.
I'm guessing it's something about SQL Server Configuration but just can't find it.
If you need to provide date&time as string literals, you learned yourself that most formats are dependent on regional and language settings.
The way to solve this is to use the (slightly adapted) ISO-8601 date format that is supported by SQL Server - this format works always - regardless of your SQL Server language and dateformat settings.
The ISO-8601 format is supported by SQL Server comes in two flavors:
YYYYMMDD for just dates (no time portion); note here: no dashes!, that's very important! YYYY-MM-DD is NOT independent of the dateformat settings in your SQL Server and will NOT work in all situations!
or:
YYYY-MM-DDTHH:MM:SS for dates and times - note here: this format has dashes (but they can be omitted), and a fixed T as delimiter between the date and time portion of your DATETIME.
This is valid for SQL Server 2000 and newer.
So in your concrete case, I'm pretty sure this query would work just fine on both your PC's:
select df_id
from diasferiados
where df_dia = '2017-09-17T17:20:03'
If you use SQL Server 2008 or newer and the DATE datatype (only DATE - not DATETIME!), then you can indeed also use the YYYY-MM-DD format and that will work, too, with any settings in your SQL Server.
Don't ask me why this whole topic is so tricky and somewhat confusing - that's just the way it is. But with the YYYYMMDD format, you should be fine for any version of SQL Server and for any language and dateformat setting in your SQL Server.
The recommendation for SQL Server 2008 and newer is to use DATE if you only need the date portion, and DATETIME2(n) when you need both date and time. You should try to start phasing out the DATETIME datatype if ever possible
We get data delivered to us in a flat file. A date column we want to store in a destination column called DWValidFrom has the following format:
2017-02-06T22:07:09Z
In SSIS using a Flat File Connection Manager, I set the datatype of said column to DT_DBTIMESTAMPOFFSET. It correctly shows us when checking the data in the Columns and Preview pages of the Connection Manager.
In SQL Server, I created the destination table, and defined the DWValidFrom column as datetimeoffset(0):
[DWValidFrom] [datetimeoffset](0) NOT NULL,
When I attempt to set the mappings in the OLE DB Destination object, which has been set to the SQL Server table in question, SSIS won't have it, and throws the following error:
The OLE DB provider used by the OLE DB adapter cannot convert between types "DT_DBTIMESTAMPOFFSET" and "DT_WSTR" for "DWValidFrom".
Suspecting something off with my regional settings, I issued the following query in Management Studio to ensure the format of the date wouldn't change:
SELECT CAST('2017-02-06T22:07:09Z' AS datetimeoffset(0))
This yielded the following result:
2017-02-06 22:07:09 +00:00
Why is SSIS not recognizing the column's proper data type? I do not have any other conversions or expressions set, so I'm confused as to why SSIS won't allow me to push a valid datetimeoffset.
We're using SQL Server 2014, Visual Studio 2015.
Thanks.
This sounds like the OLEDB source metadata is out of sync with the changes you made on the flat file connection manager. The quickest fix it would be to recreate the OLEDB source, but don't do that quite yet.
SSIS is not going to like that standard ISO format for the date. If you remove the "T" in the middle and the "Z" at the end it be ok. i.e.
2017-02-06 22:07:09
Because of this conversion issue in SSIS, the connection manager will probably fail in converting the string to datetimeoffset. So you will need to configure it as a string and then fix it's value in a derived column:
(DT_DBTIMESTAMPOFFSET, 0) REPLACE(REPLACE( [DWValidFrom] , "T", " " ), "Z", "")
Hope that helps,
m
The issue seemed to be that the OLEDB destination does not recognize datetimeoffset as a valid column format. Despite everything working in SQL Server and SSIS pushing a datetime that would be perfectly valid, the OLEDB destination wouldn't have any of it.
I considered using a SQL Server destination, but because the target server is a different server than the one we develop on, that wasn't an option either.
The fix for us was to instead format the columns using datetime as a datatype, which causes us to loose the timezone info, but because all of the dates were UTC, we really don't miss any data.
Quick Answer: Set DataTypeCompatibility to 0
I noticed in Connection Manager for my SQL Server Native Client 11.0 (OLEDB) connection, clicking on "All", then under the SQLNCLI11.1 section there's a value DataTypeCompatibility which was set to "80". 80 is code for SQL Server 2000 compatibility, well before they introduced TimeStampOffset (or in my case DT_DBDATE and DT_DBTIME2 types). I tried setting compatibility to 130, then 100, but "Test Connection" failed.
At https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/using-connection-string-keywords-with-sql-server-native-client?view=sql-server-2017 there's a table, specifying information about this value
DataTypeCompatibility SSPROP_INIT_DATATYPECOMPATIBILITY Specifies the mode of data type handling to use. Recognized values are "0" for provider data types and "80" for SQL Server 2000 data types.
Changing the value to 0, then refreshing all of my connections using the OLEDB connection manager seems to have done the trick - now all my database's types are recognized rather than forcing it to nvarchar/DT_WSTR
Changing date time of server stops Execution of SSIS package, How to test time dependency? (Error at the bottom)
I have an SSIS package that uses 3 servers,
1.Server A to get data from
2.Server B to insert data into
3.Server C is where the SSIS package lives and gets executed from.
I have a select logic depending on GetDate() when getting data from server A,
For testing, Changing date on Server C to activate the logic depending on GetDate() does not apply the expected logic.
Changing the Date on all 3 servers or just server A and C, or just C causes error : "Description: Unable to load the package as XML because of package does not have a valid XML format. A specific XML parser error will be posted."
The same SSIS package runs as expected when changing the date on dev machine as all 3 database reside on the same server on the dev machine.
Why the hell loading of XML depends on what date it is??
messing with system date & time may put you into trouble difficult to debug (as you already discovered).
remove the dependency on GETDATE() replacing it with a variable/parameter; when running in production that parameter will be filled by a GETDATE() but when testing you can replace it with a value of your choice.