I know this sounds backwards but I would like to be able to determine what authentication mode a SQL server is in prior to connecting with credentials. Is this possible?
In case you’re interested, I’ll briefly explain why…
The majority of the users of our product don’t know, understand or even care about the database underlying their business application. Traditionally we have simply installed SQL Server 2005 Express silently as part of the installation, with a SQL user and password embedded in the application. For the majority of ‘Ma and Pa’ companies we’ve sold to over the past 10 years, this has been enough.
As security concerns are becoming more prominent and our product is starting to reach some larger scale users (with IT consultants or even staff of their own that do have a clue about security) some with their own pre-existing (pre ‘our product’ being installed) SQL servers we find we are needing to fit into existing environements more flexibly.
I don’t have a problem with that, but I do not want to force decisions about SQL server authentication methods, user names and passwords etc, etc, onto our ‘lowest common denominator’ user, at installation.
If that’s all to hard, we lose them before we even get started.
So, I would like for our application to be able to determine quickly and easily what mode the server is running in, and build its connection string appropriately.
Currently we are simply using trial and error – try to connect with Windows Authentication, connect? = good, fail? = try with SQL and the known user name/password, connect? = good, fail? now prompt for credentials because in this scenario they must have changed stuff and therefore have an idea about what they are doing.
Is ‘trial and error’ the only way or is there a way to check authentication mode before connecting with credentials? (Using c# and sql2005 for what it’s worth)
For what it’s worth, I’m not sure checking the authentication mode prior to attempting a connection is going to help.
If the authentication mode is Windows Auth, you won’t know until you try to connect whether the identity of the current user has login rights.
If the authentication mode is Mixed Auth, there’s no guarantee that the account & password you specify is going to work either – so I don’t think you have an alternative but to use trial and error.