Wednesday, March 21, 2012

Problem with 64-bit ODBC code and SQLConnect and SQLWCHAR

Hi all,
I'm trying to test some 64-bit ODBC stuff and I'm running into a slight
problem. First, my configuration.
Windows XP x64
VS.Net 2005 Beta 2
SQL Server 2005 CTP
So, I have built and tested other 64 bit apps so I know that things are all
working, but now I'm trying to test ODBC and I'm running into a problem. I
have the following code :
SQLCHAR Database[MAXBUFLEN]; // = "Cloud";
SQLCHAR User[MAXBUFLEN]; // = "fred";
SQLCHAR Pass[MAXBUFLEN]; // = "me";
sprintf ((char *)Database, "%s", "Cloud");
sprintf ((char *)User, "%s", "fred");
sprintf ((char *)Pass, "%s", "me");
retcode = SQLConnect(hdbc1, Database, SQL_NTS,
User, SQL_NTS, Pass, SQL_NTS);
If I execute this code as part of a little test program on my 32 bit box, it
connects just fine. Now, to get this code to compile on the 64-bit box, I
have to cast the string variable with (SQLWCHAR *) like this.
retcode = SQLConnect(hdbc1, (SQLWCHAR *)Database, SQL_NTS,
(SQLWCHAR *)User, SQL_NTS, (SQLWCHAR *)Pass, SQL_NTS);
So it compiles, but when I run it, I get an error back. If I take a look
at what (SQLWCHAR *)Database produces, its some unreadable junk. If I turn
on ODBC logging and then after the SQLConnect call take a look at the log,
where I should see the database for instance, I see just random characters.
So, what gives ? Do I have to do something special when working with
SQLWCHAR ?
Thanks for any help anyone can give me.
Nick
Hi
SQL Server 2005 CTP questions to the community newsgroups:
http://communities.microsoft.com/new...r2005&slcid=us
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Nick Palmer" <nick@.kcicorp.com> wrote in message
news:11i480ff7qiikf9@.corp.supernews.com...
> Hi all,
> I'm trying to test some 64-bit ODBC stuff and I'm running into a slight
> problem. First, my configuration.
> Windows XP x64
> VS.Net 2005 Beta 2
> SQL Server 2005 CTP
> So, I have built and tested other 64 bit apps so I know that things are
> all
> working, but now I'm trying to test ODBC and I'm running into a problem.
> I
> have the following code :
> SQLCHAR Database[MAXBUFLEN]; // = "Cloud";
> SQLCHAR User[MAXBUFLEN]; // = "fred";
> SQLCHAR Pass[MAXBUFLEN]; // = "me";
> sprintf ((char *)Database, "%s", "Cloud");
> sprintf ((char *)User, "%s", "fred");
> sprintf ((char *)Pass, "%s", "me");
> retcode = SQLConnect(hdbc1, Database, SQL_NTS,
> User, SQL_NTS, Pass, SQL_NTS);
> If I execute this code as part of a little test program on my 32 bit box,
> it
> connects just fine. Now, to get this code to compile on the 64-bit box, I
> have to cast the string variable with (SQLWCHAR *) like this.
> retcode = SQLConnect(hdbc1, (SQLWCHAR *)Database, SQL_NTS,
> (SQLWCHAR *)User, SQL_NTS, (SQLWCHAR *)Pass, SQL_NTS);
> So it compiles, but when I run it, I get an error back. If I take a look
> at what (SQLWCHAR *)Database produces, its some unreadable junk. If I
> turn
> on ODBC logging and then after the SQLConnect call take a look at the log,
> where I should see the database for instance, I see just random
> characters.
> So, what gives ? Do I have to do something special when working with
> SQLWCHAR ?
> Thanks for any help anyone can give me.
> Nick
>

No comments:

Post a Comment