DSN Creation through SQLConfigDataSource() funciton
-
Hi, The following sample failed to create the DSN, void main() { //As my DB path will change frequently i am using this method. bool aDSNCreated = false; char temp[MAX_PATH]; sprintf(temp,"DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)\0", temp); printf("%d",aDSNCreated ); } whereas when I execute the below code; it execute successfully.Can anyone help in this why its happening? void main() { bool aDSNCreated = false; aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); printf("%d",aDSNCreated ); }
-
Hi, The following sample failed to create the DSN, void main() { //As my DB path will change frequently i am using this method. bool aDSNCreated = false; char temp[MAX_PATH]; sprintf(temp,"DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)\0", temp); printf("%d",aDSNCreated ); } whereas when I execute the below code; it execute successfully.Can anyone help in this why its happening? void main() { bool aDSNCreated = false; aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); printf("%d",aDSNCreated ); }
DurgaDevi_hr wrote:
"Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"
Interesting string format with a double Null-Terminator[^], what were they thinking? The extra Null-Terminator will cause problems with most C-Runtime string functions. Have a look at SQLConfigDataSource attributes with variables[^], does this help? /M
Webchat in Europe :java: (only 4K)
-
DurgaDevi_hr wrote:
"Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"
Interesting string format with a double Null-Terminator[^], what were they thinking? The extra Null-Terminator will cause problems with most C-Runtime string functions. Have a look at SQLConfigDataSource attributes with variables[^], does this help? /M
Webchat in Europe :java: (only 4K)
Hi Moak, I tried the logic as specified in the link. It worked fine. Thanks for that. But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string? Any idea about that? :)
-
Hi Moak, I tried the logic as specified in the link. It worked fine. Thanks for that. But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string? Any idea about that? :)
DurgaDevi_hr wrote:
But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string?
In a nutshell, the
SQLConfigDataSource()
uses a strange string format and with a literal text string this is fortunately not a problem (your second example code). But when you use string functions such assprintf/strcpy/strlen
they will stop at the first Null-Terminator. For example"bla\0fasel\0"
would be copied only to the the first \0 and becomes"bla\0"
. You can try it in the debugger. :)Webchat in Europe :java: (only 4K)
modified on Monday, December 14, 2009 7:53 AM
-
DurgaDevi_hr wrote:
But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string?
In a nutshell, the
SQLConfigDataSource()
uses a strange string format and with a literal text string this is fortunately not a problem (your second example code). But when you use string functions such assprintf/strcpy/strlen
they will stop at the first Null-Terminator. For example"bla\0fasel\0"
would be copied only to the the first \0 and becomes"bla\0"
. You can try it in the debugger. :)Webchat in Europe :java: (only 4K)
modified on Monday, December 14, 2009 7:53 AM
Tanx for ur reply!!
-
Hi, The following sample failed to create the DSN, void main() { //As my DB path will change frequently i am using this method. bool aDSNCreated = false; char temp[MAX_PATH]; sprintf(temp,"DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)\0", temp); printf("%d",aDSNCreated ); } whereas when I execute the below code; it execute successfully.Can anyone help in this why its happening? void main() { bool aDSNCreated = false; aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); printf("%d",aDSNCreated ); }
DurgaDevi_hr wrote:
The following sample failed to create the DSN,
So then why aren't you calling
SQLInstallerError()
to find out why?"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