C
C#3mo ago
Abdesol

Tried many things to fix this SqlClient exceptions, but no hope

It is a started project given to me, and I have to run the project first, and then exectue the stored procedures. We are using SQL Server for this. I am facing the below error as I run the project
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "database_name" requested by the login. The login failed.
Login failed for user 'User'.
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "database_name" requested by the login. The login failed.
Login failed for user 'User'.
And when I manually create the database instead of relying on the project to create it, I get the below error which I think is looking for the table:
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Table_Name'.
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Table_Name'.
I tried with windows authentication as well as sql server authentication by creating new logins, but it keeps resulting on the same error. It is working for them, it is just not working on my pc. What are the possible things I could do to fix this issue? Thank you!
8 Replies
becquerel
becquerel3mo ago
do you have the relevant permissions for database_name? your login can be valid and just not have the required permissions, both via windows auth and sql server auth
Abdesol
AbdesolOP3mo ago
They said just run the project and it will create the database as well. but after creating the db, manually, and giving my login the db owner and all the other permissions, I face this error:
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Table_Name'.
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Table_Name'.
becquerel
becquerel3mo ago
if they're saying the project will create the database, i'm not sure why you would make the DB manually it sounds like they're expecting the code to run migrations on startup it's hard for me to give advice on that front without seeing the code
Abdesol
AbdesolOP3mo ago
yeah, they are expecting that. Do you think SQL Server might behave differently from system to system, or the way they are describing it will work just accidently somehow worked? I am requesting the backup of the db to load it on my side to avoid all these issues. I hope this will fix it, but if not, I am cooked
becquerel
becquerel3mo ago
it depends on where the sql server instance lives... if it's running in a docker container then everything should be close to deterministic. but if it's a real instance living on a server somewhere, all bets are off lol. are you able to connect to the server through SSMS/azure data studio/etc.?
Abdesol
AbdesolOP3mo ago
I am able to connect to it through SSMS and it is not running on docker container.. it is just directly on my pc now
becquerel
becquerel3mo ago
so the same login works in SSMS, but not in your app code? hmm is your app using a valid connection string (the same as you're using in SSMS)?
Abdesol
AbdesolOP3mo ago
Server=localhost; Database=database_name;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;Integrated Security=True;
Server=localhost; Database=database_name;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;Integrated Security=True;
This is what I am using I am also logging in with the window's authentication on SSMS
Want results from more Discord servers?
Add your server