SQL ODBC Batch file question

Question...I have a bat file I wrote to create an ODBC connection, but I wanted to set it up with SA user authentication.  How do I add that into my current code along with the password?
cd C:\WINDOWS\system32
"odbcconf.exe" /a {CONFIGSYSDSN "SQL Server" "DSN=tkcsdb|Description=tkcsdb|SERVER=vsapp9|Network=MAHC|Trusted_Connection=Yes|Database=tkcsdb"}

pause
@CLS
@EXIT

Open in new window

LVL 1
Black_FlagAsked:
Who is Participating?
 
Jim P.Commented:
Back under my expert hat:

All my googling kept coming back to the same MSDN SQL server forum that basically says "you can't create a SQL Authentication DSN with odbcconf and shouldn't use SQL Authentication anyway." Grrr! :-(

So that means you're probably going to have to do it as a two file solution. You can either copy or have a central point that store the registry entry like the one shown below.
 
Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
    "ExampleDSN"="SQL Server"  
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ExampleDSN]
    "Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll"
    "Description"="To give details"
    "Server"="ServerName"
    "QuotedId"="No"
    "AnsiNPW"="No"
    "Database"="AdventureWorks"
    "LastUser"="sa"
    "AutoTranslate"="No"

Open in new window


Then in your batch file have something like this command
%SystemRoot%\regedit.exe -s X:\MyPath\MyODBC.reg

Open in new window


If you want to you can build the .reg file on the fly out of your batch file. If you want to go that route, let me know and I can tell you how to do it.
0
 
Black_FlagAuthor Commented:
Any help on this would be appreciated!!!
0
 
Jim P.Commented:
It should be something like this:
cd C:\WINDOWS\system32
"odbcconf.exe" /a {CONFIGSYSDSN "SQL Server" "DSN=tkcsdb|Description=tkcsdb|SERVER=vsapp9|Network=MAHC|Trusted_Connection=No|LastUser=sa|Database=tkcsdb"}

pause
@CLS
@EXIT

Open in new window


I usually build a file and load it via regedit:
Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
    "ExampleDSN"="SQL Server"  
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ExampleDSN]
    "Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll"
    "Description"="To give details"
    "Server"="ServerName"
    "QuotedId"="No"
    "AnsiNPW"="No"
    "Database"="AdventureWorks"
    "LastUser"="sa"
    "AutoTranslate"="No"

Open in new window



You can read more about it here: Creating DSNs for SQL Server: In depth on how to make one.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Black_FlagAuthor Commented:
THanks!  Is there a spot where I have to put a password in though or no?
0
 
Jim P.Commented:
You can't save the password in the ODBC call. That has to be handled by your application. As an example if your were to link from an MS Access db, there is a hidden table called MSysobjects. The Connect column would look something like this:
 
DSN=TCL;UID=AppMGR;PWD=password;APP=Microsoft Office XP;AutoTranslate=No;QuotedId=No;AnsiNPW=No

Open in new window

0
 
ReneGeCommented:
In reference to : 37354575
You could also try adding the key:
"PWD"="ThePassword"

Let me know if it works.
0
 
Black_FlagAuthor Commented:
So you mean something like this?
cd C:\WINDOWS\system32
"odbcconf.exe" /a {CONFIGSYSDSN "SQL Server" "DSN=tkcsdb|Description=tkcsdb|SERVER=vsapp9|Network=MAHC|Trusted_Connection=No|LastUser=sa|PWD=password|Database=tkcsdb"}

pause
@CLS
@EXIT

Open in new window

0
 
Jim P.Commented:
ReneGe,

I tried that in the past. The SQL Server and SQL Native Client drivers are designed to deliberately to ignore it. Some other drivers can and do support that withe either plain text or encrypted passwords.

Would you want every person that had access to the registry to be able to see your plain text password?

0
 
Black_FlagAuthor Commented:
damn!  I thought that original code was going to work...turns out im getting this error....any ideas? error error
0
 
ReneGeCommented:
I just realised it was about "SQL Server" not "MySQL".

Sorry for that ;(
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.