sql - Error : Login failed for user 'domain\username' using SqlCredential object -



sql - Error : Login failed for user 'domain\username' using SqlCredential object -

i using below mentioned code when tried connect sql server. geeting login failed user 'domain\username'. have checked user having sysadmin permission in sql server & using sql server express edition.

connection string used "initial catalog=employee;server=servername"

public static bool connectsqlclient(string connecton) { bool isconnect = false; seek { string username = @"domain\username"; string initstring = "abcpassowrd"; // instantiate secure string. securestring teststring = new securestring(); // utilize appendchar method add together each char value secure string. foreach (char ch in initstring) teststring.appendchar(ch); teststring.makereadonly(); sqlcredential cred = new sqlcredential(username, teststring); sqlconnection conn = new sqlconnection(connecton, cred); conn.open(); isconnect = true; } grab (exception) { throw; } homecoming isconnect; }

let me know if missed something.

typically, when add together login sql server, there 2 modes.

sql server authentication (which "old school" user-name , pwd scenario)

and

"windows authentication". find user (domain\username) on network , add together login. scenario not require password set/sent.

server=myserveraddress;database=mydatabase;trusted_connection=true;

that typical "windows authentication" connection string. don't set username/pwd, because iidentity "picked up" who/whatever logged or credentials application running.

i ~think want utilize windows-authentication (since mention 'domain/username')....but you're setting pwd if using sql-server-authentication. "mixing" 2 models.

as mkross mentions, because add together login, still need "link in" database itself. if go security/logins/ (properties) , go "user mapping" selection, can "map" database, , select role_membership "db_datareader" low rights role.

append:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcredential%28v=vs.110%29.aspx

sqlcredential provides more secure way specify password login effort using sql server authentication. sqlcredential comprised of user id , password used sql server authentication.

so yeah, that's sql-server-authentication. not windows-authentication.

you need

string myconnectionstring = "server=myserveraddress;database=mydatabase;trusted_connection=true;"

sql sql-server sqlconnection

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -