Programmatically setting SqlServer vs. Windows authentication

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am wondering how to programmatically select either SqlServer or Windows
authentication when connecting to a database. Is this something in the
connection string? Or is it some other parameter to a connection method...?
 
Michael,

Yes, it is in the connection string. To facilitate generating this
programatically, take a look at the SqlConnectionStringBuilder class in the
System.Data.SqlClient namespace.
 
Both replies so far contain useful information on this topic; however they do
not really help me with my base question. Perhaps a specific example may
clarify. Let's say that I want to connect to AdventureWorks. I know that this
string works using Windows Authentication:

Data Source=.\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated
Security=True

Now let's say I create a new SQL user and want to change to SqlServer
authentication. So I add the "User ID" and "Password" attributes to the
connection string. Is that all it takes? Do I need to add other attributes?
Or remove the "Integrated Security" ...?
 
Both replies so far contain useful information on this topic; however they do
not really help me with my base question. Perhaps a specific example may
clarify. Let's say that I want to connect to AdventureWorks. I know that this
string works using Windows Authentication:

Data Source=.\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated
Security=True

Now let's say I create a new SQL user and want to change to SqlServer
authentication. So I add the "User ID" and "Password" attributes to the
connection string. Is that all it takes? Do I need to add other attributes?
Or remove the "Integrated Security" ...?

There are so many variations of connection strings it is easy to
forget exactly what you need...I find the following resource helpful


http://carlprothman.net/Default.aspx?tabid=81
 
Hi,

As other community members suggested, you will need to remove the
"Integrity Security" and add "User ID"/Password to make it use sqlserver
authentication.

Please feel free to let us know if there's still anything unclear. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top