August 21, 2009 at 10:04 am
Hello all,
I have an application that creates databases programmaticaly. Before the user can create the database, he has to provide an username and a password, which corresponds to the username and the password of a SQL Server login. What i can't do, is to find the way the SQL Server will check the user-provided info and answer if they are valid or not.
Thanks in Advance,
Alex.
August 21, 2009 at 12:38 pm
I am not sure about the authentication you may have to do the authentication before using the code in the link below which connects to the Master and create any database through ADO.NET.
http://support.microsoft.com/kb/305079
Kind regards,
Gift Peddie
August 21, 2009 at 2:26 pm
use sqlconnectionstringbuilder class:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx
basically, what you want to do is use the above class to set username/password for connection string.
use try/catch block to open a connection, and if try works you can let the user create the database using a login that has database creation permissions. if you happen to catch connection denied then they can't create a database because they specified wrong username/password. i don't have visual studio close by to see if it tries to connect to the server when you open a connection or if it waits until you try to execute a sql statement. if the later is the case, you can use a simple select statement like "select 1" to see if the login is correct.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply