StrataFrame Forum

Getting the provider type

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

By Andria Jensen - 7/20/2006

How do I get the provider type from the data source?  I would like to know whether I am looking at a SQL, Oracle, DB2, etc. database.  Also, is there any way other than parsing the connection string to get out the Server, Database Name, User ID, and Password? 
By Trent L. Taylor - 7/20/2006

There are several options.  You can test on the data source type to determine which provider is being used based on the type of object which would probably be the easiest.

Dim loType As System.Type = MicroFour.StrataFrame.Data.DataBasics.DataSources.Item("").GetType()

        If loType Is GetType(MicroFour.StrataFrame.Data.SqlDataSourceItem) Then
            MsgBox("SQL Server")
        ElseIf loType Is GetType(MicroFour.StrataFrame.Data.OracleDataSourceItem) Then
            MsgBox("Oracle")
        ElseIf loType Is GetType(MicroFour.StrataFrame.Data.VfpDataSourceItem) Then
            MsgBox("VFP")
        ElseIf loType Is GetType(MicroFour.StrataFrame.Data.AccessDataSourceItem) Then
            MsgBox("Access")
        End If

 

By Andria Jensen - 7/20/2006

Ok, that works for getting the type.  Is there any way to get the other information I referred to like Database Name, User ID, Password, and Server?  I can parse the connection string, but this seems a little unreliable.
By Trent L. Taylor - 7/20/2006

Once you determine the type, use a ConnectionStringBuilder, pass it the connection string, and it will parse it for you.

Dim loConn As New System.Data.SqlClient.SqlConnectionStringBuilder(MicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString)

        MsgBox(loConn.DataSource)
        MsgBox(loConn.UserID)
        MsgBox(loConn.Password)

By Andria Jensen - 7/20/2006

Great!  thanks.
By Trent L. Taylor - 7/21/2006

No problem Smile