1

I have this code:

    Dim myConn As SqlConnection
    Dim cmd As SqlCommand
    Dim sqlstring, DNAME, DEXP, DCREATION, DLASTUPDATE, DCOMMENTS As String

    DNAME = TextBox1.Text
    DEXP = TextBox2.Text
    DCREATION = TextBox3.Text
    DLASTUPDATE = TextBox4.Text
    DCOMMENTS = TextBox5.Text


    myConn = New SqlConnection("Integrated Security=SSPI;Data Source=.;Initial Catalog=DOMAIN_NAME;User ID=sa;Password=***********")

    myConn.Open()

    sqlstring = " INSERT INTO ROLAND (D_NAME, D_EXPIRATION, D_CREATION, D_LASTUPDATE,D_COMMENTS) VALUES ('" + DNAME + "','" + DEXP + "','" + DCREATION + "','" + DLASTUPDATE + "','" + DCOMMENTS + "')"

    cmd = New SqlCommand(sqlstring, myConn)

    cmd.ExecuteNonQuery()

    myConn.Close()

    Response.Redirect(Request.RawUrl, True)

When I execute, it gives me this error:

Cannot open database "DOMAIN_NAME" requested by the login. The login failed.
Login failed for user 'comm-pc10\pcuser10.comm'.

and it highlights myConn.Open()

What is the problem here, any help ? I have SQLServer 2008 and a user name and pass for my database

2
  • 3
    I recommend you to figure out how to do parameterized queries in vb. Concatenating the insert statement like you do leaves you wide open for SQL injection. littlebobbytables.com Commented Nov 21, 2011 at 13:18
  • Even worse as he uses SA account Commented Nov 21, 2011 at 13:21

4 Answers 4

2

You have integrated security ON, which means SQL server uses Windows authentification and therefore ignores your user and password setting. I guess your windows user does not have access to the database.

Set "Integrated security=false" to use username/password.

0
1

You are using Integrated Security=SSPI which is linked with window use authentication. Either you should add that user to database for remove this .

0
0

The problem is the connection string :

Initial Catalog = Database Name Not Domain Name

and make sure that your user id and password is correct and Data Source is the correct server address.

see this for more into : Connection Strings

0

'this code help to accessing several records from the database using vb.net 2010 'sunil sir

    Imports System

    Imports System.Data

    Imports System.Data.SqlClient

    Imports System.Data.DataSet

    Imports System.Data.SqlTypes


    Public Class insert_extracode
        Dim i As Int16
        Private Sub insert_extracode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            i = 0

        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim con As New SqlConnection

            Dim cmd As New SqlCommand

            Dim adp As New SqlDataAdapter

            Dim data As New DataSet

            con.ConnectionString = "Data Source=DELL-PC\SQLEXPRESS;Initial Catalog=hotel;Integrated Security=True"

            cmd.Connection = con

            Dim str As String = "select * from customer"

            cmd = New SqlCommand(str, con)

            adp = New SqlDataAdapter(cmd)

            adp.Fill(data)

            TextBox1.Text = data.Tables(0).Rows(i).Item(0)
            TextBox2.Text = data.Tables(0).Rows(i).Item(1)
            TextBox3.Text = data.Tables(0).Rows(i).Item(2)
            i = i + 1
        End Sub
    End Class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.