Solved

SQLConfigDataSource failed !

Posted on 2004-04-30
11
897 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 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