Solved

SQLConfigDataSource failed !

Posted on 2004-04-30
11
884 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
  • 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
 

Author Comment

by:mike_marquet
ID: 10975165
To  Mafalda :

   It's the same => function failed
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 45 total points
ID: 10975826
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 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.

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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now