Search code examples
vb.netpathconnection-stringrelative-path

VB.NET relative path connection string


I need to make this connection string into a relative path so I can move my program from PC to PC without having to change the connection string every time. This is what I have in VB.NET:

 con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\Chris\Desktop\Newfolder\PizzaEmporium.mdf"";Integrated Security = True;Connect Timeout=30"

I get kind of lost on some of the examples from the Internet.


Solution

  • Dim Path As String = Environment.CurrentDirectory
    
    Dim con As String = "Data Source=(LocalDB)\v11.0; AttachDbFilename=" & Path &
      "\PizzaEmporium.mdf;Integrated Security=True;Connect Timeout=30"