1

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.

2 Answers 2

1
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"
Sign up to request clarification or add additional context in comments.

1 Comment

Strings concatenation should use the" &" to concate, just a thought.
0

Get the path of the current directory with:

 Dim path As String = Environment.CurrentDirectory

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.