When I was trying to connect to SQL Server using the following code:
SqlConnection con = new SqlConnection("Server=localhost,Authentication=Windows Authentication, Database=employeedetails"); con.Open(); SqlCommand cmd; string s = "delete employee where empid=103";
I get the following error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)
A connection made using Windows Authentication is sometimes called a trusted connection, because SQL Server trusts the credentials provided by Windows. By using Windows Authentication, Windows groups can be created at the domain level, and a login can be created on SQL Server for the entire group.
Windows authentication means the account resides in Active Directory for the Domain. SQL Server knows to check AD to see if the account is active, password works, and then checks what level of permissions are granted to the single SQL server instance when using this account.
Right-click the server you wish to modify and then click Properties. Select the Security Page. Under the Server authentication heading choose either the desired authentication: Windows Authentication or SQL Server and Windows Authentication mode. Click OK.
Resolution to SQL error code 18456Go to the Properties of the selected server (from the right-click menu). Now go to the Security page and under Server authentication choose the option SQL Server and Window Authentication mode. Now expand Security > Logins and right-click the server name, and select Properties.
A connection string for SQL Server should look more like: "Server= localhost; Database= employeedetails; Integrated Security=True;"
If you have a named instance of SQL Server, you'll need to add that as well, e.g., "Server=localhost\sqlexpress"
Your connection string is wrong
<connectionStrings> <add name="ConnStringDb1" connectionString="Data Source=localhost\SQLSERVER;Initial Catalog=YourDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With