Some one help me here
my problem is on the

conn.Open()

it stated that "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"


here's my code

Dim str As String = "server=localhost.;uid=root;pwd=;database=sample"
        Dim conn As New SqlConnection(str)

        conn.Open()
        Dim sql As String = "INSERT INTO tblpicture VALUES(@surname,@givenname,@middlename,@age ,@gender ,@religion ,@civilstatus,@DOB , @POB, @home_address,@edu , @tring, @tele_no.,@mobile_no.,@picture)"
        Dim cmd As New SqlCommand(sql, conn)

        cmd.Parameters.AddWithValue("@surname", surname.Text)
        cmd.Parameters.AddWithValue("@givenname", givenname.Text)
        cmd.Parameters.AddWithValue("@middlename", middlename.Text)
        cmd.Parameters.AddWithValue("@age", age.Text)
        cmd.Parameters.AddWithValue("@gender", gender.Text)
        cmd.Parameters.AddWithValue("@religion", religion.Text)
        cmd.Parameters.AddWithValue("@civilstatus", civilstatus.Text)
        cmd.Parameters.AddWithValue("@DOB", DOB.Text)
        cmd.Parameters.AddWithValue("@POB", POB.Text)
        cmd.Parameters.AddWithValue("@home_address", home_address.Text)
        cmd.Parameters.AddWithValue("@edu", edu.Text)
        cmd.Parameters.AddWithValue("@tring", tring.Text)
        cmd.Parameters.AddWithValue("@tele_no.", telephone.Text)
        cmd.Parameters.AddWithValue("@mobile_no.", mobile.Text)

        Dim ms As New MemoryStream()
        PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
        Dim data As Byte() = ms.GetBuffer()
        Dim p As New SqlParameter("@picture", SqlDbType.Image)

        p.Value = data
        cmd.Parameters.Add(p)
        cmd.ExecuteNonQuery()
        MessageBox.Show("Record has been saved", "Save", MessageBoxButtons.OK)

        conn.Close()
    End Sub

help me plss

Recommended Answers

All 4 Replies

The SQL standard connection string looks like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

What you have there looks more like a MySQL database connection string.

The SQL standard connection string looks like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

What you have there looks more like a MySQL database connection string.

another error was occur sir when i do what you've said

Dim conn As New SqlConnection(str)

it said " Format of the initialization string does not conform to specification starting at index 37."

should local host have a period after it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.