string conversion problems

A

alex

i have the following line in my console app:

_bstr_t strCnn("my database connection string");

with the database connection string hard coded as above, it works, i connect
to my db.

when i read the db connection string into a string variable from the console
and try to use it or something i converted it into as the argument to strCnn
I can't connect. Any help would be appreciated.

ps

I know _bstr_t is not part of standard C++, it's a C++ class from microsoft.

there's info on _bstr_t all over the web but i still can't get my code to
work so i'm posting here.
 
G

Gregg

I know _bstr_t is not part of standard C++, it's a C++ class from
microsoft.

there's info on _bstr_t all over the web but i still can't get my code
to work so i'm posting here.

A better place to ask about a Microsoft library class would be a Microsoft
newsgroup. Try one of these:

microsoft.public.vc.language
microsoft.public.vc.stl
microsoft.public.vc.atl

If your news server doesn't carry these groups, you can get them on
Microsoft's server at msnews.microsoft.com. There are hundreds of
libraries, dozens of operating systems and dozens of compilers, and if
people were to post about all these in here, it would get very noisy.

Gregg
 
J

John Ericson

alex said:
i have the following line in my console app:

_bstr_t strCnn("my database connection string");

with the database connection string hard coded as above, it works, i connect
to my db.

when i read the db connection string into a string variable from the console
and try to use it or something i converted it into as the argument to strCnn
I can't connect. Any help would be appreciated.

ps

I know _bstr_t is not part of standard C++, it's a C++ class from microsoft.

there's info on _bstr_t all over the web but i still can't get my code to
work so i'm posting here.
<snip>

<OT>
Just out of morbid curiosity, what exactly happened when you
tried
string dasfk = "my database connection string";
const _bstr_t strCnn(dasfk.c_str());
</OT>
 
P

Phlip

Gregg said:
A better place to ask about a Microsoft library class would be a Microsoft
newsgroup. Try one of these:

microsoft.public.vc.language
microsoft.public.vc.stl
microsoft.public.vc.atl

If your news server doesn't carry these groups, you can get them on
Microsoft's server at msnews.microsoft.com. There are hundreds of
libraries, dozens of operating systems and dozens of compilers, and if
people were to post about all these in here, it would get very noisy.

And our replies would get much less accurate.

Sure I know how Gtk+'s gchar works!!
 
A

alex

John Ericson said:
<snip>

<OT>
Just out of morbid curiosity, what exactly happened when you
tried
string dasfk = "my database connection string";
const _bstr_t strCnn(dasfk.c_str());
</OT>

this works, i love you man
 
A

alex

bad news

string dasfk = "my database connection string";
const _bstr_t strCnn(dasfk.c_str());

the above works but when i use the string variable that took the console
input or assign that string variable to dasfk, it doesn't work. The error
message in this and most other cases is SQL Server does not exist or access
denied.

i know the variable has the connection string in it because i display it to
output after it's read in from the console.
 
P

Peter Kragh

alex said:
bad news

string dasfk = "my database connection string";
const _bstr_t strCnn(dasfk.c_str());

the above works but when i use the string variable that took the console
input or assign that string variable to dasfk, it doesn't work. The error
message in this and most other cases is SQL Server does not exist or access
denied.

i know the variable has the connection string in it because i display it to
output after it's read in from the console.

Hint: Have you tried to look at the contents of your strings in the
debugger?
 
R

Rolf Magnus

Please don't top-post.
bad news

string dasfk = "my database connection string";
const _bstr_t strCnn(dasfk.c_str());

the above works but when i use the string variable that took the
console input or assign that string variable to dasfk, it doesn't
work. The error message in this and most other cases is SQL Server
does not exist or access denied.

It heavily depends on how _bstr_t works. Since many people here (like
me) don't know anything about that type, it's hard to give an accurate
answer. If the constructor of that class doesn't make a copy of the
string data, you might get into trouble. The pointer that c_str()
returns is only valid as long as the string is not modified or deleted.
 
J

Jorge Rivera

alex said:
the above works but when i use the string variable that took the console
input or assign that string variable to dasfk, it doesn't work. The error
message in this and most other cases is SQL Server does not exist or access
denied.
It seems like the work of the comp.lang.c++ is done. I think your
chances of getting relevant change in this newsgroup have degraded
significantly.

Try an MS newsgroup.
i know the variable has the connection string in it because i display it to
output after it's read in from the console.
You can be mislead by console output.
 
A

alex

Jorge Rivera said:
It seems like the work of the comp.lang.c++ is done. I think your
chances of getting relevant change in this newsgroup have degraded
significantly.

Try an MS newsgroup.

You can be mislead by console output.

i've verified using breakpoints as well, the problem is the variable type, i
need to do proper conversion from console input and i haven't gotten the
conversion right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,463
Latest member
FinleyMoye

Latest Threads

Top