Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27532

VS 2012 DbProviderFactory - Experiences

$
0
0
Here is my first experience with DbProviderFactory.

Code:

        'Dim dbf As Data.Common.DbProviderFactory = Data.Common.DbProviderFactories.GetFactory("IBM.Data.DB2.iSeries")
        Dim dbf As Data.Common.DbProviderFactory = Data.Common.DbProviderFactories.GetFactory("System.Data.SqlClient")
        Dim conn As Data.Common.DbConnection = dbf.CreateConnection
        conn.ConnectionString = "theconnectionstring"

        Dim sql As XElement =
            <sql>
                --- test
                SELECT * FROM Tablename
            </sql>
        Dim cmnd As Data.Common.DbCommand = dbf.CreateCommand
        cmnd.CommandType = CommandType.Text
        cmnd.CommandText = sql.Value.ToString

        conn.Open()
        Dim rdr As System.Data.Common.DbDataReader = cmnd.ExecuteReader
        If rdr.HasRows Then
            Do While rdr.Read
                'blah, blah
            Loop
        End If
        rdr.Close()
        conn.Close()
        conn.Dispose()

This worked great with the SqlClient but when I changed it to the IBM client it failed. It opened the connection but never returned rows, and if you executed the code more than once I would get an error, SQL0519 Prepared statement S000001.

After spending almost a day on this I found out that it would execute if I removed the comment or if added
Code:

cmnd.Prepare()
before the ExecuteReader.

In another part of the code, where I was doing inserts, the .Prepare caused the SqlClient to complain about not setting .Size for variable length fields.


As a first experience this has not been good or I have done something wrong. Has anyone else done this or used DbProviderFactory extensively and know the gotchas?

The point of all of this was to prove how easy it would be to switch from (DB2, Sql, MySQL, etc.) to (DB2, Sql, MySQL, etc.).

One other thing, that may or may not be related to DbProviderFactory. Columns define as 'Time' on DB2 and SQL have different data types when read with the reader.

Viewing all articles
Browse latest Browse all 27532

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>