I am using `Environment.CurrentDirectory` to get the current directory, i.e. **"D:\Chuttu\Projects\LIC\bin\Debug"**

But, I want to remove **"\bin\Debug"**

How can I do that? Or is there any way so that I can get the directory up to **"LIC\"**?

Actually this is my connection string:

```
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\LIC.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

```

But when I use this and try to insert data into the DB, the data is not inserted. When I use the connection string with a physical path it starts working:

```
Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Chuttu VB\Projects\LIC\LIC.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

```

I am trying to get the physical path of the `mdf` file and use it in the connection string.

---

EDIT:

This piece of code works fine:

```
Private Sub save()
        Dim con As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Chuttu VB\Projects\LIC\LIC.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

        Dim sql As New SqlClient.SqlCommand("INSERT INTO ProposerDetails " & _
                                            "VALUES (" & Convert.ToInt32(PolicyNumberTextBox.Text) & ",'" & NameTextBox.Text & "','" & AgeTextBox.Text & "','" & PhoneTextBox.Text & "','" & AddressTextBox.Text & "','" _
                                            & NomineeTextBox.Text & "','" & NomineeRelationTextBox.Text & "'," & PlanID() & ",'" & PolicyTermTextBox.Text & "','" & PremiumAmountTextBox.Text & "','" _
                                            & PremiumTypeComboBox.Text & "','" & SumProposedTextBox.Text & "','Date' )", con)

        MsgBox(sql.CommandText)
        con.Open()

        MsgBox(con.State.ToString)
        Dim i As Integer = sql.ExecuteNonQuery
        MsgBox(i.ToString)
        con.Close()
        sql.Dispose()
        con.Dispose()
        ToolStripStatusLabelMessage.Text = "Saved"
    End Sub

```

As soon as I change the connection string to the connection string from app.config it stops working (adding data to DB):

```
Private Sub save()
        Dim con As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\LIC.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

        Dim sql As New SqlClient.SqlCommand("INSERT INTO ProposerDetails " & _
                                            "VALUES (" & Convert.ToInt32(PolicyNumberTextBox.Text) & ",'" & NameTextBox.Text & "','" & AgeTextBox.Text & "','" & PhoneTextBox.Text & "','" & AddressTextBox.Text & "','" _
                                            & NomineeTextBox.Text & "','" & NomineeRelationTextBox.Text & "'," & PlanID() & ",'" & PolicyTermTextBox.Text & "','" & PremiumAmountTextBox.Text & "','" _
                                            & PremiumTypeComboBox.Text & "','" & SumProposedTextBox.Text & "','Date' )", con)

        MsgBox(sql.CommandText)
        con.Open()

        MsgBox(con.State.ToString)
        Dim i As Integer = sql.ExecuteNonQuery
        MsgBox(i.ToString)
        con.Close()
        sql.Dispose()
        con.Dispose()
        ToolStripStatusLabelMessage.Text = "Saved"
    End Sub

```

NOTE: I get no errors.