[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1062
  • Last Modified:

Need help with Sql Server connection string

HI,
I am copying some code from another uses software to my project and i am quite new in vb.net

from the user code, the connection string is :

 BCon = New sqlConnection("data source=micron;uid=sa;pwd=admin;initial catalog=gsmlanka")
 cartCon = New sqlConnection("data source=micron;uid=sa;pwd=admin;initial catalog=gsmlanka")
I can see, he used sql server username and password for his development
but in my pc , i am using sqlserver but windows authentication

I am trying with bellow code but its not working :


BCon = New sqlConnection("Data Source=GRAPHICS\sqlexpress;initial catalog=gsmlanka;Integrated Security=True")
 cartCon = New sqlConnection("Data Source=GRAPHICS\sqlexpress;initial catalog=gsmlanka;Integrated Security=True")

Error is below :

Cannot open database "gsmlanka" requested by the login. The login failed.
Login failed for user 'GRAPHICS\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "gsmlanka" requested by the login. The login failed.
Login failed for user 'GRAPHICS\ASPNET'.


Do i need to give some permission ?


but its not working , can any one tell me where i am doing wrong?
0
fosiul01
Asked:
fosiul01
  • 6
  • 6
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, you have to create the windows login in the sql server logins and grant the permissions to the database you want to connect to.
0
 
fosiul01Author Commented:
Hi
Sql server login is already windows login.
But how i will grant permission ??
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Sql server login is already windows login.
you mean, sql server is configured to allow windows authentication?

that alone is not sufficient, you have to create a login in the sql server security that maps the windows login, and from there grant the permissions. see the below tip to show the screenshots (screenshot 2 is what you need to do):
http://www.acucorp.com/support/public/tech_tips/tips/tips_36.php

once such a login is created, you can (and have to) grant the permissions to the databases as to a normal sql login.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
fosiul01Author Commented:
Hi, i am using Sql server  2005
I attached 2 pictures,
one is sqlserver management studio  express
other is: i connect other database frm vb.net (web sites), and its works , i didnot have to give any permission for anything.


Sqlserver2005.GIF
vb.net.GIF
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that is how you try to connect.

the problem is not there, but in the logins defined.
you have to connect with a login that has the permission to connect, and create the logins as needed...

only then you can connect with a dedicated windows account.

note: by default, the local (on the sql box) windows administrators can connect using windows authentication...
0
 
fosiul01Author Commented:
omm, in that case
will you able to tell me, step by step, how to solve this issue please, as i said, i dont have enough knowledge about th is issue, i am learning
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
step 0: start sql management studio using a login that has permissions to create logins
 
then:
http://technet.microsoft.com/en-us/library/aa337562.aspx
<...>
   1. In SQL Server Management Studio, open Object Explorer and expand the folder of the server instance in which to create the new login.
   2. Right-click the Security folder, point to New, and then click Login.
   3. On the General page, enter the name of a Windows user in the Login name box.
   4. Select Windows Authentication.
   5. Click OK.
0
 
fosiul01Author Commented:
Hi
thanks
now i am getting following error :

Server Error in '/' Application.
--------------------------------------------------------------------------------

SELECT permission denied on object 'Manufacturer', database 'gsmlanka', schema 'dbo'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SELECT permission denied on object 'Manufacturer', database 'gsmlanka', schema 'dbo'.

Source Error:


Line 5:  BCmd = New sqlCommand("select * from manufacturer order by man_id asc",Bcon )
Line 6:  Bcon.Open()
Line 7:  phnList.DataSource = BCmd.ExecuteReader()
Line 8:  phnList.DataBind()
Line 9:  BCon.Close()
 

Source File: c:\inetpub\wwwroot\shop\man_menu.aspx    Line: 7
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that is step 2:
grant the select permissions for the user based on that login in your database for that table... ie for the other tables.
you might also grant the db_datareader role to that login, in case you want to have this user (login) read on all the tables in that database...
0
 
fosiul01Author Commented:
ok check 2 p ictures i have attached, tell where i am doing wrong,
i gave all permission as you said
still same error



sqlsstudio.GIF
sqlstudio1.GIF
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you checked the db_denydatareader (and db_denydatawriter) roles, which override any other permissions to read (write) data.
uncheck those (at least), ie you should only have the db_datareader (and db_datawriter) checked for a normal login, all the others should not be checked..
0
 
fosiul01Author Commented:
Done!!!
Thanks to help me to find out this soliution.


0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now