[Solved] can not connect to sql in C# visual studio can not login [closed]


As others have said, it’s a little difficult to guess what your problem might be. It’s probable that you are using Windows Authentication, and you are running Visual Studio (and so your program when you hit f5) as the windows user “DESKTOP-FHI3”. If this is your problem, you could grant this user access to your database.

If you do have the required access to the database you are trying to access as another user, you can connect and grant access to users by using the interface in SQL Server Management Studio, or Visual Studio’s SQL Server Object Explorer. You could also run a SQL script using one of these tools to do the same. For example the following script would grant a windows user, DESKTOP-FH13 db_owner level access to your database.

USE [master]
GO
CREATE LOGIN [<YourDomainName>\DESKTOP-FHI3] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
USE <YourDatabaseName>
GO
CREATE USER [<YourDomainName>\DESKTOP-FHI3] FOR LOGIN [<YourDomainName>\DESKTOP-FHI3]
GO
USE <YourDatabaseName>
GO
ALTER ROLE [db_owner] ADD MEMBER [<YourDomainName>\DESKTOP-FHI3]
GO

An alternate solution would be to create a SQL User, and use that instead of using Windows Authentication. If you did this, you would also need to update your connection string, stating Integrated Security=FALSE, and adding “User ID=…;Password=….”.

1

solved can not connect to sql in C# visual studio can not login [closed]