Using Test data or live data depending on application setting in .Net?
I have seen it done where someone has set up two application settings; one containing the test data connection string and the other containing the live data connection string. They use the same dbml no matter which actual database they are pointed to, then whenever they set the data context they just sp开发者_JS百科ecify the setting they would like to use. I would like to implement this, but was wondering if there are any good blog posts or tutorial showing how to do this correctly, or if there is a more "out-of-the-box" alternative.
Config transformations based on build type?
Here's what I use:
Friend Sub connect(ByVal isDebuggerAttached As Boolean)
Dim server As String
Dim dbName As String
If isDebuggerAttached Then
server = "DHSDEV10069\DSD"
Else
server = "dhs10073sql"
End If
dbName = "DSDWorkPlanTracking"
_connect = "Data Source=" & server & ";Database=" & dbName & ";Integrated Security=true"
_connect = _connect & ";Application Name = " & My.Application.Info.AssemblyName
End Sub
and in the calling class:
Try
Model.instance.connect(System.Diagnostics.Debugger.IsAttached)
Catch ex As Exception
MsgBox("Sorry, couldn't connect to database " & ex.Message)
End Try
Also, for Help/About:
Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
Dim msg As String
Dim appName As String
If My.Application.Info.Title <> "" Then
appName = My.Application.Info.Title
Else
appName = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
End If
msg = appName & vbCrLf & vbCrLf
msg = msg & "Version: " & Application.ProductVersion & vbCrLf & vbCrLf ' the file version displayed in .exe properties. Assembly version is for internal builds and doesn't need to change for one developer.
msg = msg & "User: " & My.User.Name & vbCrLf & vbCrLf
msg = msg & "Connection: " & Model.instance.connection & vbCrLf & vbCrLf
MsgBox(msg, MsgBoxStyle.OkOnly, appName)
End Sub
精彩评论