For one part of my app I need to authenticate the details of a users SQL account.
The way this is currently done is to append the username and password to the connectionstring and then return a dataset with the users details. This code lives in a try statement and if there an exception is thrown it assumes the user details were incorrect (a very nasty way of doing things.).
The current code is something like this:
iBindClientServices.Services service = new iBindClientServices.Services(); //nasty com+ service
try
{
string szConn = "DSN=xxxxx" + ";UID=" + userName + ";PWD=" + password;
//check username and password
ADODB.Recordset record = service.GetUserDetail(szConn, "");
}
catch(Exception ex)
{
//login unsuccessfull
}
Is there an elegant way to do this?
How about this piece of code
public static bool checkConnection()
{
SqlConnection conn = new SqlConnection("mydatasource");
try
{
conn.Open();
return true;
}
catch (Exception ex) { return false; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.