Solved

SQLConfigDataSource failed !

Posted on 2004-04-30
11
907 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

807 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