Click here to Skip to main content
15,881,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
st = "Data source =eduDotNet-Pc06; Initial Catalog=My_database; Integrated security=true";
         cn = new SqlConnection(st);
            try
            {
                cn.Open();

            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
Posted
Comments
Herman<T>.Instance 23-Oct-12 8:35am    
sometimes you have to set Integrated security=sspi in stead of true. don't ask me why. Is your account added to the logins and users in the database system?

This is rather straight-forward: the login you are running this code under does not have permissions to this database. When you use "Integrated Security=true", you are saying that the application will take the permissions of the user running it. If this is a desktop application, it is going to be the logged on individual. If it is a service, it will take on the permissions that the service runs under. If it is a web application, it will take on the permissions of the application pool it is using.

To fix the error, figure out who you are running under and make sure to give them the appropriate permissions.
 
Share this answer
 
Comments
zeshanazam 23-Oct-12 8:39am    
how to give them the appropriate permissions. ?? using windows xp.
Tim Corey 23-Oct-12 8:45am    
The permissions are at the database level, not the operating system level. You would need to identify which accounts need access to the database and then add those accounts to the security in the database. How you do that depends on your database type that you are using. Your other option would be to use a local database user instead of integrated security. I would recommend you look into database security before you continue just to make sure you know what you are doing and why.
Please verify that are you able to login in database seperatly , if also not there then stop the service for DB and change the credential form there and restart the service .

Thanks,
Ambesha
 
Share this answer
 
Comments
zeshanazam 23-Oct-12 8:57am    
I HAVE TRIED EVERY THING, BUT PROBLEM IS SAME....
please try this...



st = "Data source =eduDotNet-Pc06; Initial Catalog=My_database; Integrated security=SSPI"; User Id=myUsername; Password=myPassword;



Please Let Me know ur feed back

Thanks
lp
 
Share this answer
 

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