Login failed for user 'sa'. in connection string

后端 未结 2 822
小鲜肉
小鲜肉 2020-12-21 16:41

I\'m getting the following error:

Login failed for user \'sa\'

When I try to connect server by setting value through a string v

相关标签:
2条回答
  • 2020-12-21 16:48

    Maybe the server name and the database name (in the dbname and catname variables) are just wrong?

    BTW, i would recommend using the SqlConnectionStringBuilder class.

    var sb = new SqlConnectionStringBuilder() { InitialCatalog = catname,
                                                DataSource = dbname,
                                                UserID = "sa",
                                                Password = "sa" };
    
    var dbConnection = new SqlConnection(sb.ConnectionString);
    
    0 讨论(0)
  • 2020-12-21 17:14

    put your connectionstring in web.config file as I show below

    <connectionStrings>
    <add name="Test" connectionString="data source=Harsh; Initial Catalog=Test ; user Id=sa; password=sa123;"/>
    </connectionStrings>
    

    Above "Test" is connectionstringname,you can write your datasource name.Mine is Harsh,so changed it according to yours.Give your database name in inital catalog.

    And then put this code in your code behind page load event

    SqlConnection con = new  SqlConnection(ConfigurationManager.ConnectionStrings["Test"].ToString());
    

    It will work.

    0 讨论(0)
提交回复
热议问题