Wednesday, March 21, 2012

Login failed for the user (using windows integrated security)

Hello Everyone,

I am trying to connect SQL database through code but I get this error,I have spent days to solve it but unfortunately I couldn't...Here is my code in VB express(OP:windows 2000 with SP4)I am new to VB,so it makes the situation more difficult for me.

my code is:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn1 As SqlConnection = _

New SqlConnection("Data Source=.\SQLEXPRESS;" & _

"Integrated Security=SSPI;" & _

"database=deneme3_database;")

'Open connection

conn1.Open()

MessageBox.Show("Connection succeeded.")

'Close connection

conn1.Close()

MessageBox.Show("Connection closed.")

End Sub

The error message is,it is in german but it is clear I guess:)

" Die von der Anmeldung angeforderte "deneme3_database"-Datenbank kann nicht ge?ffnet werden. Fehler bei der Anmeldung.
Fehler bei der Anmeldung für den Benutzer 'ADPLAN\atalay'. "

Thank you in advance!

Can

The database mentioned in the connection string under database or Initial catalog is not present on the server or not accessible to the user. So either grant additional rights to the user or choose another database for the initial connection.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Hallo,

First of all I'd like to thank you for your reply.

The mentioned database was also created by me ,using new project in VB express and was also saved on the same PC. I don't actually know how to get permission to use it...I am new to VB and SQL so it makes the things a bit difficult for me.I also enable TCP/IP connection and pipes in SQL Express Server and also disabled the firewall but anyway I get the same error...

I have to write a program connecting to an external device and get the data from the device and compare it with the data in SQL database.But I stucked in the beginning...

Regards,

Can

|||

For a quick one, try to add the user to the sysadmin group to let him access the database (if it is based on a security issue)

sp_addsrvrolemember [ @.loginame= ] 'login'
, [ @.rolename = ] 'role'


For granular configuration, use the following procedure to grant him access to the db (not any objects so far)

sp_grantlogin [@.loginame=] 'login'
sp_defaultdb [ @.loginame = ] 'login', [ @.defdb = ] 'database'
sp_grantdbaccess [ @.loginame = ] 'login'
[ , [ @.name_in_db = ] 'name_in_db' [ OUTPUT ] ]

The same can be done within the Managment Studio.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de


|||

Hi Mr. Suessmeyer,

Again thank you for your reply...But I don't know where to enter this code in SSMS...It'd be kind of you you if you could explain it to me a bit more detailed.I am new to SQL and VB...Thank you!

Can

|||

hi Can,

outcast1881 wrote:

Hi Mr. Suessmeyer,

Again thank you for your reply...But I don't know where to enter this code in SSMS...It'd be kind of you you if you could explain it to me a bit more detailed.I am new to SQL and VB...Thank you!

Can

you can execute the statemets Jens provided via any tool able to send command to SQL Server... for your convenience, you can download and use SQL Server Management Studio Express, the free graphical management tool for SQLExpress at http://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&displaylang=en..

after connecting to the required SQL Server instance, you can open a "new query" window and execute them...

the very same tool provides a graphical interface to manage Logins, database Users and the like..

regards

No comments:

Post a Comment