Bug in 3.1?
Posted: Wed 20 Jul 2005 22:35
I am using the following code to create a table:
If PVar.OutputFormat.Oracle Then
Dim connection As New OracleConnection
Dim command As New OracleCommand
Try
connection.Close()
connection.UserId = gsPVarMgr.SQLServerUserName
connection.Server = gsPVarMgr.SQLServerName
connection.Password = gsPVarMgr.SQLServerPassword
connection.Open()
command.Connection = connection
command.CommandType = CommandType.Text
command.CommandText = "CREATE TABLE " & GetDBNameForOracle(CurrOutputDBName, myTableName) & " ("
Dim first As Boolean = True
For Each mycol In myTable.Columns
Dim ColumnType As String = ""
Dim ColumnName As String = ""
If first Then first = False Else ColumnName &= ","
ColumnName &= """" & mycol.ColumnName & """"
Select Case mycol.DataType.Name
Case "Single"
ColumnType = "BINARY_FLOAT"
Case "Double"
ColumnType = "BINARY_DOUBLE"
Case "String"
ColumnType = "VARCHAR2(255)"
Case "Int32"
ColumnType = "LONG"
Case "Boolean"
ColumnType = "LONG"
Case "Object"
ColumnType = "BLOB"
Case "DateTime", "Date"
ColumnType = "DATE"
Case Else
myEventMessage.OnAM("Bad type for column in output database", AMessageType.StandardError)
connection.Close()
Return
End Select
command.CommandText &= ColumnName & " " & ColumnType
Next
command.CommandText &= ")"
command.ExecuteNonQuery()
connection.Close()
Return
When I try using loader, to load the table, I get the following error:
LoadTime: 20-Jul-05 1:36:36 PM CurrTime: 20-Jul-05 3:26:57 PM Error: System.InvalidOperationException: Table contains field with data type that does not supported by OracleLoader.
at CoreLab.Oracle.OracleLoader.Open()
at AURORAServer.clsdbOutputMain.WriteTable(DataTable mytable, String mytablename) in C:\VBNet\AURORAXMPSolution\AURORAServer\clsdbOutputMain.vb:line 641
Code is the following (error occurs at loader.open :
If PVar.OutputFormat.Oracle Then
Dim connection As New OracleConnection
Dim column As New OracleLoaderColumn
Dim loader As New OracleLoader
Try
Dim myOracleTableName As String = GetDBNameForOracle(CurrOutputDBName, mytable.TableName)
connection.Close()
connection.UserId = gsPVarMgr.SQLServerUserName
connection.Server = gsPVarMgr.SQLServerName
connection.Password = gsPVarMgr.SQLServerPassword
connection.Open()
loader.Connection = connection
loader.TableName = myOracleTableName
If Not HoldLoaderCols.Contains(myOracleTableName) Then
loader.CreateColumns()
For Each mycol As OracleLoaderColumn In loader.Columns
mycol.Name = "`" & mycol.Name & "`"
Next
HoldLoaderCols.Add(myOracleTableName, loader.Columns)
Else
For Each myloadercol As OracleLoaderColumn In HoldLoaderCols.Item(myOracleTableName)
loader.Columns.Add(myloadercol)
Next
End If
loader.Open()
Dim myColFlag() As Boolean
ReDim myColFlag(mytable.Columns.Count - 1)
Dim ii As Integer = 0
For Each mycol As OracleLoaderColumn In loader.Columns
If mycol.OracleDbType = OracleDbType.Float Then
myColFlag(ii) = True
Else
myColFlag(ii) = False
End If
ii += 1
Next
For Each myrow As DataRow In mytable.Rows
Dim i As Integer = 0
For Each mycol As DataColumn In mytable.Columns
If myColFlag(i) Then
If Not IsDBNull(myrow.Item(i)) Then
If Single.IsInfinity(myrow.Item(i)) Then
myrow.Item(i) = DBNull.Value
End If
End If
End If
loader.SetValue(i, myrow.Item(i))
i += 1
Next
loader.NextRow()
Next
loader.Close()
connection.Close()
Catch e As Exception
myEventMessage.OnAM(e.ToString, AMessageType.StandardError)
connection.Close()
End Try
Return
End If
If PVar.OutputFormat.Oracle Then
Dim connection As New OracleConnection
Dim command As New OracleCommand
Try
connection.Close()
connection.UserId = gsPVarMgr.SQLServerUserName
connection.Server = gsPVarMgr.SQLServerName
connection.Password = gsPVarMgr.SQLServerPassword
connection.Open()
command.Connection = connection
command.CommandType = CommandType.Text
command.CommandText = "CREATE TABLE " & GetDBNameForOracle(CurrOutputDBName, myTableName) & " ("
Dim first As Boolean = True
For Each mycol In myTable.Columns
Dim ColumnType As String = ""
Dim ColumnName As String = ""
If first Then first = False Else ColumnName &= ","
ColumnName &= """" & mycol.ColumnName & """"
Select Case mycol.DataType.Name
Case "Single"
ColumnType = "BINARY_FLOAT"
Case "Double"
ColumnType = "BINARY_DOUBLE"
Case "String"
ColumnType = "VARCHAR2(255)"
Case "Int32"
ColumnType = "LONG"
Case "Boolean"
ColumnType = "LONG"
Case "Object"
ColumnType = "BLOB"
Case "DateTime", "Date"
ColumnType = "DATE"
Case Else
myEventMessage.OnAM("Bad type for column in output database", AMessageType.StandardError)
connection.Close()
Return
End Select
command.CommandText &= ColumnName & " " & ColumnType
Next
command.CommandText &= ")"
command.ExecuteNonQuery()
connection.Close()
Return
When I try using loader, to load the table, I get the following error:
LoadTime: 20-Jul-05 1:36:36 PM CurrTime: 20-Jul-05 3:26:57 PM Error: System.InvalidOperationException: Table contains field with data type that does not supported by OracleLoader.
at CoreLab.Oracle.OracleLoader.Open()
at AURORAServer.clsdbOutputMain.WriteTable(DataTable mytable, String mytablename) in C:\VBNet\AURORAXMPSolution\AURORAServer\clsdbOutputMain.vb:line 641
Code is the following (error occurs at loader.open :
If PVar.OutputFormat.Oracle Then
Dim connection As New OracleConnection
Dim column As New OracleLoaderColumn
Dim loader As New OracleLoader
Try
Dim myOracleTableName As String = GetDBNameForOracle(CurrOutputDBName, mytable.TableName)
connection.Close()
connection.UserId = gsPVarMgr.SQLServerUserName
connection.Server = gsPVarMgr.SQLServerName
connection.Password = gsPVarMgr.SQLServerPassword
connection.Open()
loader.Connection = connection
loader.TableName = myOracleTableName
If Not HoldLoaderCols.Contains(myOracleTableName) Then
loader.CreateColumns()
For Each mycol As OracleLoaderColumn In loader.Columns
mycol.Name = "`" & mycol.Name & "`"
Next
HoldLoaderCols.Add(myOracleTableName, loader.Columns)
Else
For Each myloadercol As OracleLoaderColumn In HoldLoaderCols.Item(myOracleTableName)
loader.Columns.Add(myloadercol)
Next
End If
loader.Open()
Dim myColFlag() As Boolean
ReDim myColFlag(mytable.Columns.Count - 1)
Dim ii As Integer = 0
For Each mycol As OracleLoaderColumn In loader.Columns
If mycol.OracleDbType = OracleDbType.Float Then
myColFlag(ii) = True
Else
myColFlag(ii) = False
End If
ii += 1
Next
For Each myrow As DataRow In mytable.Rows
Dim i As Integer = 0
For Each mycol As DataColumn In mytable.Columns
If myColFlag(i) Then
If Not IsDBNull(myrow.Item(i)) Then
If Single.IsInfinity(myrow.Item(i)) Then
myrow.Item(i) = DBNull.Value
End If
End If
End If
loader.SetValue(i, myrow.Item(i))
i += 1
Next
loader.NextRow()
Next
loader.Close()
connection.Close()
Catch e As Exception
myEventMessage.OnAM(e.ToString, AMessageType.StandardError)
connection.Close()
End Try
Return
End If