Hi,
I use pIDBPromptInitialize interface for establish a connection to MS SQL Server 2005.
SQL Server has “us_english” (LCID=1033) language as default setting.
I use the following part of code to charge LCID (from 1033 to 1049):
CDBPropSet ps3;
ps3.SetGUID(DBPROPSET_DBINIT );
ps3.AddProperty(DBPROP_INIT_LCID, (long)1049);
hr= pIDBProperties->SetProperties(1, &ps3);
hr= pIDBPromptInitialize->PromptDataSource(NULL, GetActiveWindow(),
DBPROMPTOPTIONS_PROPERTYSHEET,
0, NULL, (LPOLESTR)szFilter,
IID_IDBProperties, (IUnknown **)(&pIDBProperties));
...
hr = FDS->Connection->m_spInit->Initialize();
Then I connect to SQL Server successfully.
But SQL Server has LCID=1033 anyway!! Way I didn’t change it by my code? What is wrong?
But later I try to use some feature of LCID=1049 (date conversation)
How can I change “Language” setting to, for example, Russian (LCID=1049) using pIDBPromptInitialize
G.Can you elaborate on what do you do exactly? Which actions are you expecting to be affected by LCID setting?|||
Hi Anton,
I have MS SQL Server 2005 with LCID = 1033 (english).
As result the datetime format is mdy.
I have the table t1 with the following structure:
create table t1 ([Date] datetime not null, [d1] int);
which has the following data:
[Date] [d1]
--
2007-05-12 00:00:00.000 100
2007-05-13 00:00:00.000 200
2007-05-14 00:00:00.000 300
2007-05-15 00:00:00.000 400
Next, I have a OLEDB C++ client application, which makes and executes the following command:
CString cmd;
COleDateTime dt;
dt= COleDateTime::GetCurrentTime();
cmd.Format(L”select * from [t1] where [Date]= ‘%s’”, dt.Format(VAR_DATEVALUEONLY, LOCALE_USER_DEFAULT)
...
For me, the LOCALE_USER_DEFAULT value is 1049.
It is important to pay attention that LCID of MSSQL Server is 1033 and LCID of client application is 1049.
Next...
After formatting, my oledb command looks like this:
select * from [t1] where [Date]= ’14.05.2007’
and result of execution I get SQL Server error: convert is not possible. It is because MS SQL Server parse the ’14.05.2007’ date using not appropriate datetime formar.
My goal is to set LCID of SQL Server oledb connection as I need (in example above to 1049).
PS
I can’t use the ‘set dateformat dmy’ command.
PS2
Of cause, I could use the following command:
FLCID= 1033;
...
cmd.Format(L”select * from [t1] where [Date]= ‘%s’”, dt.Format(VAR_DATEVALUEONLY, FLCID);
...
But it isn’t my goal.
Best regards,
SGN
|||Could you try using a parameterized query? I think in that case the data will be passed to the server in a binary form if you provide a corresponding binding, so you could avoid a conversion to string.|||Take a look at GetDateFormat function - http://msdn2.microsoft.com/en-us/library/ms776293.aspx
Hope this helps
|||Hi,
Thank you for your replay!
Regarding usage of the GetDateFormat function I have another question.
It concern not only SQL Server but ALL OLEDB datasources.
How can I know the LCID of OLEDB datasource which I can use as datastorage?
Is it possible to get current LCID of OLEDB datasource using OLEDB functionality only?
Thank you for your help!
Best regards,
SGN
|||I'm not sure if there is a generic OLEDB way.
Session language for the SQL Server is a provider specific property SSPROP_INIT_CURRENTLANGUAGE.
http://msdn2.microsoft.com/en-us/library/ms142797.aspx
For sqlserver you can also change the language by executing sp_configure, and the list of supported languages can be produced by sp_helplanguage. Default language for the login can alos be overriden at hte session level by executing SET LANGUAGE.
No comments:
Post a Comment