Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQLConfigDataSource failed !

Posted on 2004-04-30
11
Medium Priority
?
950 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

597 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