StrataFrame Forum

Retrieve Server and Database and Login information

http://forum.strataframe.net/Topic12836.aspx

By Michael Reese - 11/27/2007


I can get the connectioninfo from;

MicroFour.StrataFrame.Data.DataLayer.DataSources.Item(0).ConnectionString.ToString

However, I How can I separedly retrieve the following from my SF project?

Server Name

Database Name

Server Login

Thanks

By Greg McGuffey - 11/27/2007

The connection string is usually a set of key=value pairs, delimited by semi-colons. So, a bit of string manipulation will get you there. Just use the Split function on semi-colons first, then split on each pair on using '='. Either just test each as you go or you could add them to a dictionary, so you could then just access each value by its key.



Hope that makes sense! BigGrin
By Michael Reese - 11/28/2007

Yeah, I was hoping that I would not have to go that route!

Thanks much!

By Trent L. Taylor - 11/28/2007

Actually there is an easier way if you do not want to parse it yourself.  You can pass the connection string into the SqlConnectionStringBuilder class and it will parse the string for you into properties:

Dim connInfo As New SqlClient.SqlConnectionStringBuilder(DataBasics.DataSources(0).ConnectionString)
Dim msg As String = ""


msg &= connInfo.DataSource & ControlChars.CrLf
msg &= connInfo.InitialCatalog & ControlChars.CrLf
msg &= connInfo.UserID & ControlChars.CrLf
msg &= connInfo.Password & ControlChars.CrLf
msg &= connInfo.IntegratedSecurity.ToString()
MsgBox(msg)

Greg's solution is always a good workaround though if this doesn't give you what you need.