我正在编写一个通过SQL Server使用数据库的应用程序。我也用两台电脑来做。我想放入一个if语句来执行相应计算机的代码,因为我的数据库连接字符串对每台机器都是唯一的。每台计算机将使用相同但未同步的数据库。我不想一直来回跳转来改变连接字符串。
If Computer01 then
use connection-string01
else
use connection-string02
end if
答案 0 :(得分:0)
此代码将在VB.NET中返回计算机的名称
Dim ComputerName As String
ComputerName = System.Net.Dns.GetHostName
If ComputerName = Computer01 Then
'Connection String 1
Else
'Connection String 2
End If