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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Black_FlagAuthor Commented:
THanks!  Is there a spot where I have to put a password in though or no?
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.