Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Im running a c# application on PC1 and the sql server on PC2, i have configured the sql server to be accessed remote and working. So the problem now is that when i run the c# application i got this error which says 'Cannot open database "database_name" requested by the login. The login failed.'

Please help me solve this problem.

Here is my connection string:
SQL
Data Source=ip address for PC2;Initial Catalog=database_name;Persist Security Info=True;User ID=user_id;Password=my_password


What I have tried:

I have tried to change the connection string but still i got the error.
Posted
Updated 20-May-19 10:10am
v2
Comments
Bryian Tan 21-May-19 0:10am    
Have you try connect to the database using the username/password through SQL Management Studio?

The login is failing - so the most likely thing is that the ID and password combination you are using is not valid for teat SQL server instance.

Try this: Simple SQL Connection String Creation[^] and use PC1 to establish a connection to the DB via Windows. When that works, you can look at putting the string into your app.

BTW: I would strongly suggest using a hostname instead of an IP address - they tend to change when machines and / or routers are power cycled. It also means that if a computer dies, another can be given the same hostname and all apps continue to work.
 
Share this answer
 
Make sure you use the correct method of authentication: Windows or SQL Server authentication: Authentication in SQL Server | Microsoft Docs[^]
If you have a named instance of SQL Server Express you will need to add that in the connection string, e.g. "Server=123.4.5.6\sqlexpress".
Here is a good CodeProject article with an example: How to connect SQL Database to your C# program, beginner's tutorial[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900