user1000744
user1000744

Reputation: 123

Insert data into SQL Database using ASP.NET/VB.NET

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

Upvotes: 1

Views: 29013

Answers (4)

sunil Kumar
sunil Kumar

Reputation: 1

'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

Upvotes: 0

hemant
hemant

Reputation: 2445

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

Upvotes: 1

Wahtever
Wahtever

Reputation: 3678

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

Upvotes: 0

okrumnow
okrumnow

Reputation: 2416

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.

Upvotes: 2

Related Questions