Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect to a database using NT Login Authentication

Status
Not open for further replies.

NegreteO

Programmer
Apr 23, 2003
54
US
Hi,

I need that my app connects to a SQL Database using a different NT Login that the one is logged on currently on my PC, how do I define that I want to connect using a different NT login?

Can I achieve this by using a special parameter in the StringConnection property

Thanks in advance

 
Hi

it is normal practice to use other userids to access SQL databases - eg a generic "Read Only" userid.

It can be configured in the ODBC or coded (as per MS example)
cnn1.ConnectionString = "driver={SQL Server};" & _
"server=srv;uid=sa;pwd=pwd;database=Pubs"

In this example the userid is SQL based but in your case the SQL database must be configured to validate from the NT domain.

What you cannot do - is assume that if you have multiple NT mappings under different usernames it will automatically pick one of those to connect you

I hope this helps

regards

Rob
 
to Negrete0:

Why can't you provide your logon properties in the connection string ?

con.ConnectionString = "DRIVER={SQL SERVER};SERVER=(Local);
DATABASE=MyDb;uid=DOMAIN\user1;pwd=myPassword".
 
I get the next error

"Login failed for user DOMAIN\user1" using the connection string

con.ConnectionString = "DRIVER={SQL SERVER};SERVER=(Local);
DATABASE=MyDb;uid=DOMAIN\user1;pwd=myPassword"
 
What you want to do is not really possible.. At least without working outside the box..

Alternative 1

In W2K/xp there is a runas command that allows you to run an application "As an NT(Domain) account)". Your app would then be able to connect as the specific nt account. You would of course need to know the correct password to login as that person. But it should work.

connection string syntax would then simply be..

trusted_connection=yes

RunAs syntax for the OSQL tool.....
......................................................
runas /user:ComputerName\mia "osql -E"

where mia is the NT account, ComputerName would be the domain name or local computername where Mia exists and that a trusted (NT) connection will be made to your local sql server ( the -E switch specifies that the osql tool will connect as an Nt Account)

Run the following lines after giving a password..

1> select suser_sname()
2> go
result ........
ComputerName\Mia

(1 row affected)
...............................................


Next alternative..

Try logging on as that account..

Next alternative..

Using Com+ you could put your code into an "applciation" and have that "application" run as a specific Nt account..



HTH


Rob
 
If you are going to use an ID and password different than that of the logged-on user's, why not just create a database account on the SQL server itself? You could then hard-code it in your program or put it in an INI file or in a data link file or ODBC connection, or prompt the user for it, and pass it to the server in your connection string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top