VB.NET相对路径连接字符串

时间:2014-09-05 01:23:11

标签: vb.net path connection-string relative

我需要将此连接字符串设置为相对路径,以便我可以将程序从PC移动到PC,而无需每次都更改连接字符串。这就是我在VB.NET中所拥有的:

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

我对互联网上的一些例子感到很失落。

2 个答案:

答案 0 :(得分: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"

答案 1 :(得分:0)

使用以下命令获取当前目录的路径:

 Dim path As String = Environment.CurrentDirectory