Jump to content

Connectionstring Problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Guest_mohamedsaleh70@hotmail.co_*

Guest_mohamedsaleh70@hotmail.co_*
  • Guests
Hi all,
I use Visual Studio 2005 Pro. I have a problem with the connectionstring as it changes after I close and reopen the program. The first time it works fine, but after that I get an error message saying:
The (Database) already exists. Choose a different database name.
I really can not understand why? Why it connected the first time? What does this message mean? and How can we go around this problem?

#2
Void

Void

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 411 posts
It seems like you are not disconnecting. Do you have a disconnection line?
Void

#3
Guest_mohamedsaleh70@hotmail.co_*

Guest_mohamedsaleh70@hotmail.co_*
  • Guests

Void said:

It seems like you are not disconnecting. Do you have a disconnection line?

Thank you very much for your care and time. Here is a sample of my code.

    ' Create the connection string and populate the data table
        ' with data.
        Dim connectionString As String = "Integrated Security=SSPI;" & _
            "Persist Security Info = False;Initial Catalog=Northwnd;" _
            & "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL Server 2000 Sample Databases\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"
        Dim connection As New SqlConnection()
        connection.ConnectionString = connectionString
        Dim employeeAdapter As New SqlDataAdapter _
            (New SqlCommand("Select * from Employees", connection))
        connection.Open()
        employeeAdapter.Fill(employeeTable)
        
        ' Set the DataSource property of the BindingSource to the employee table.
        bindingSource1.DataSource = employeeTable

        ' Set up the binding to the ReportsTo column.
        Dim reportsToBinding As Binding = _
            textBox2.DataBindings.Add("Text", bindingSource1, "ReportsTo", _
                True)

        ' Set the NullValue property for this binding.
        reportsToBinding.NullValue = "No Manager"

        ' Set up the binding for the PictureBox using the Add method, setting
        ' the null value in method call.
        pictureBox1.DataBindings.Add("Image", bindingSource1, "Photo", _
            True, DataSourceUpdateMode.Never, _
            New Bitmap(GetType(Button), "Button.bmp"))

        ' Set up the remaining binding.
        textBox1.DataBindings.Add("Text", bindingSource1, "LastName", True)

    End Sub


#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Try adding

connection.Close
before your end sub.