|
hello guys... im trying to store time in sql database using ADO. Now im using ctime() to get time and then send it as arguments in function to be stored. But it show the following error
Conversion failed when converting Datetime from character string
NOTE:Datatype of this column is DateTime in Sql Server. Here is my code to get time
char time1[60] = "";
time_t sTime;
time(&sTime);
strcat(time1,ctime(&sTime));
printf("the time is:\t %s", time1);
Database db;
db.InsertRec(time1);
Now Here is the code for the function which inserts record in the database-----db.InsertRec()
char sTime[60] = "";
strcat_s(sTime,time1);
char query[100] = "INSERT INTO Tracks VALUES('";
strcat_s(query,sTime);
strcat_s(query,"')");
try
{
recordset->Open(query, connection.GetInterfacePtr(),ADODB::adOpenForwardOnly,ADODB::adLockReadOnly,ADODB::adCmdText);
}
catch(_com_error &e)
{ printf("\n\n%s", (LPCSTR)((_bstr_t)e.Description())); }
recordset->raw_Close();
what can be the problem?? thnx
modified on Thursday, February 17, 2011 2:38 AM
|
|
|
|
|
overloaded Name wrote: Conversion failed when converting Datetime from character string
That seems a fairly clear message. Your database expects a DateTime value and you are sending it a string.
I must get a clever new signature for 2011.
|
|
|
|
|
When I google it than I find why this error comes:
This error message appears, when SQL Server cannot convert a string to a valid DATETIME value. Check here -> [^]
Here is Sample[^] application that uses DateType value.
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
Print that query and enter it in e.g. SQL Server Enterprise Manager, and play with it there. I think that the date/time was not formatted the way the server expected it to be - e.g. "17.02.2011" instead of "2/17/2011". Fortunately, you tried it today, and not a week ago, as only a wrong value would have been recorded in the database.
If possible, change to parameterized queries - they will handle that scrap for you.
|
|
|
|
|
I am trying to access this key in my code (which is a Windows Service and is launched with admin privilege):
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture
and I keep getting the error code 5 (ERROR_ACCESS_DENIED ).
I followed this solution[^] to adjust the token privilege. This step succeeded, but then RegOpenKeyEx still returned ERROR_ACCESS_DENIED .
What else should I do to access this key?
Thanks in advance.
Maxwell Chen
|
|
|
|
|
|
Hi Cool_Dev,
I roughly had a glance on the discussion thread just now. In the thread, they came out with the solution using manifest file, right?
Answering to your question: Yes, I am on Windows 7 32-bit platform. My code is to be compiled with VC++6 and WDK 6000. So manifest files might not be the solution to this issue ... I guess.
Maxwell Chen
|
|
|
|
|
That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument.
Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.
|
|
|
|
|
Cool_Dev wrote: That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument.
Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.
Hi Cool_Dev,
1) The name KEY_WOW64_64KEY is not defined in VC++ 6. So I did not add it since the compiler said "undeclared identifier".
2) RegOpenKeyEx returns value 0 in the PHKEY argument.
3) I have been using KEY_ALL_ACCESS all the time.
4) During run-time seen on the debugger, ERROR_ACCESS_DENIED is 0x0005 and ERROR_CANTWRITE is 0x03F5 .
Please refer to the screenshot[^] on VC++2005 remote debugger.
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
Its not an answer but I have one doubt.
Are you sure that your application is launched with admin priviledge ?? I am also doing the same in Windows Service and it is working fine in XP, Windows 7 and Vista.
If my application is not lauched with admin priviledge than i get access denied error else it is working fine.
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
Hi Shilpi,
Shilpi Boosar wrote: Are you sure that your application is launched with admin priviledge ??
I think so. I right-click on the Command Prompt shortcut, and choose "Run as Admin", to open a DOS-box. And then I type the command:
MyService.exe -r
to setup and start the service.
Maxwell Chen
|
|
|
|
|
I don't think that means the service will run as admin, though.
When the service is installed, it determines what user it will run as.
Open Task Manager, find the process that represents your service and check what user account it is running under.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Open Task Manager, find the process that represents your service and check what user account it is running under. Hi Richard,
My service is running under the name SYSTEM .
(The logon session user account is "user ".)
Maxwell Chen
|
|
|
|
|
Nops if He open command prompt as "run as admin" mode and run application than it means that its application is also run as admin mode.
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
#include <windows.h>
#include <iostream>
using namespace std;
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};
struct Student{
Detail st;
DWORD code;
};
int main()
{
Student st;
}
how to write and read structure to a file using WriteFile() and ReadFile().
Some Day I Will Prove MySelf :: GOLD
modified on Saturday, February 19, 2011 9:43 AM
|
|
|
|
|
Something like
DWORD dwWritten;
BOOL result = WriteFile(hFile, &st, sizeof st, &dwWritten, NULL);
Use a similar form to read it back.
I must get a clever new signature for 2011.
|
|
|
|
|
#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};
struct Student{
Detail detail;
DWORD code;
};
int main()
{
DWORD BytesWritten=0, BytesRead=0;
Student st,read;
st.code =1;
st.detail.Name = TEXT("Williams");
st.detail.Age = 25;
st.detail.Address = TEXT("B-33 Lane 5");
HANDLE hFile = CreateFile(TEXT("C:\\demo.txt"),GENERIC_READ | GENERIC_WRITE,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if (hFile != INVALID_HANDLE_VALUE)
{
WriteFile(hFile,&st,sizeof(Student),&BytesWritten,0);
ReadFile(hFile,&read,sizeof(Student),&BytesRead,0);
CloseHandle(hFile);
cout<<read.code<<endl;
cout<<read.detail.Name;
}
else
{
cout<<"Error! Cannot Open File";
exit(1);
}
_getche();
return (0);
}
when executing this code following error occurs.
Error 1 error C2440: '=' : cannot convert from 'const wchar_t [9]' to 'wchar_t [25]'
Error 2 error C2440: '=' : cannot convert from 'const wchar_t [12]' to 'wchar_t [100]'
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
goldenrose9 wrote: st.detail.Name = TEXT("Williams");
st.detail.Address = TEXT("B-33 Lane 5");
You probably meant to use _tcscpy() here instead.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: You probably meant to use _tcscpy() here instead.
This works like a charm
_tcscpy(st.detail.Name,TEXT("Williams"));
_tcscpy(st.detail.Address,TEXT("B-33 Lane 5"));
But another problem arises cannot set values in long and DWORD variables
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};
struct Student{
Detail detail;
DWORD code;
};
Student st;
st.code = 1;
but st.code stores a default value of -16843010 and same problem with long data type st.Details.Age = 25 stores 65278, instead of 25.
MODIFIED:
_tcscpy_s() now works. i was making a small mistake. Now it works..
_tcscpy_s(st.detail.Name,_tcslen(st.detail.Name),TEXT("WILLIAMS"));
Some Day I Will Prove MySelf :: GOLD
modified on Wednesday, February 16, 2011 10:43 PM
|
|
|
|
|
goldenrose9 wrote: why error is occurring in _tcscpy_s()
Hard to say since you did not indicate what the error was.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Try ZeroMemory
Student st,read;
ZeroMemory(&st,sizeof(st));
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
To OP: This is only meaningful if you don't intend to initialize every member separately.
|
|
|
|
|
goldenrose9 wrote: i was making a small mistake.
And you still are. _tcslen() does not tell you the size/capacity of Name , but rather how many characters it is currently holding.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
yes you are right. but when i use
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
stack around st get corrupted.
moreover when i initialize st with
st.code =1;
st.detail.Age = 25;
then the value is changed to
st.code = 4278124286
st.detail.Age = -16843010
i had intialized the st as given
st.code =1;
st.detail.Age = 25;
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
_tcscpy_s(st.detail.Address,sizeof(st.detail.Address),TEXT("BB-33 LANE 5"));
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
Have you considered:
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));
For clarities sake, you might consider renaming the st member of Student .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|