?
Solved

SQLConfigDataSource failed !

Posted on 2004-04-30
11
Medium Priority
?
936 Views
Last Modified: 2007-12-19
How to use this function to create a system DSN with trusted connection = NO

AND user = xxx

AND password = yyy

I have tried this without success :

  char *szDriver = "SQL Server";

  char *szAttributes = "DSN=BMSDDSN\0"
                       "SERVER=(local)\0"
                       "TRUSTED_CONNECTION=no\0"
                       "DATABASE=CleanEditDB\0"
                       "UID=bmssa\0"
                       "PWD=bmssa_pwd\0";

  RETCODE retCode = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, szDriver, szAttributes);


If I don't add UID and PWD, the function works, but I must specify the user and password

Any idea ?
0
Comment
Question by:mike_marquet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 Comments
 
LVL 6

Expert Comment

by:Mafalda
ID: 10961350
What was the return code ?

Maybe you should try

  char szDriver[] = "SQL Server";

  char szAttributes[] = "DSN=BMSDDSN\0"
                       "SERVER=(local)\0"
                       "TRUSTED_CONNECTION=no\0"
                       "DATABASE=CleanEditDB\0"
                       "UID=bmssa\0"
                       "PWD=bmssa_pwd\0";


0
 
LVL 1

Expert Comment

by:Last_Inquisitor
ID: 10971163
You must terminate the stringlist with TWO zeros:

...
PWD=bmssa_pwd\0\0
0
 

Author Comment

by:mike_marquet
ID: 10975153
Already try it but it's the same => function failed
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mike_marquet
ID: 10975165
To  Mafalda :

   It's the same => function failed
0
 
LVL 6

Expert Comment

by:Mafalda
ID: 10975344
"List of attributes in the form "keyname=value". These strings are separated by null terminators with two consecutive null terminators at the end of the list."

So Last_Inquisitor is correct, and although the MS example in the same page has one null terminator it should have two ...

Try doing it directly and see what happens


RETCODE retCode = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN,  "SQL Server",
  "DSN=BMSDDSN\0"
  "SERVER=(local)\0"
  "TRUSTED_CONNECTION=no\0"
  "DATABASE=CleanEditDB\0"
  "UID=bmssa\0"
  "PWD=bmssa_pwd\0\0"); // note two nulls here

0
 

Author Comment

by:mike_marquet
ID: 10975406
I have already tried with a second NULL terminator but function failed also.

If I look in MSDN for function prototype, I can see a table with keynames that can be use.

I never see the keyname : UID and keyname : PWD

And what say up is that without UID and PWD keynames, the function is working with or without a second NULL terminator.

The C++ language set the second NULL character itself.
0
 
LVL 6

Expert Comment

by:Mafalda
ID: 10975718
Right,
Sorry I missed that ;o)
I think that the name and password are passed at the stage that you use the SQLConnect function

"Connects to a specific driver by data source name, user ID, and password"

0
 
LVL 6

Expert Comment

by:Mafalda
ID: 10975739
Data Sources do not contain name and password ... the DB does.
Try administrating a data source with the Administrator tool and you will see that there are no names an passwords
0
 
LVL 6

Accepted Solution

by:
Mafalda earned 180 total points
ID: 10975826
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question