Forum Discussion

mtejjini's avatar
mtejjini
New Contributor III
8 months ago

Type 'SqlBulkCopy' is not defined.

Hello everyone,
I am trying to create a table in OS with the fx rates by calling an API
while calling the API, i can get the data needed but i have this error <Type 'SqlBulkCopy' is not defined.> that's doesn't allow me to copy the data in a table in OS.

this is a part of the code, the lines in orange are the ones not working.

'create table '
#Region "Create Table Currencies_Mantu"
Dim sSQL As String = $"
IF OBJECT_ID('Table_rate_mantu') IS NOT NULL
BEGIN
    DROP TABLE Table_rate_mantu
END
 
CREATE TABLE Table_rate_mantu (
    
 
    fromCurrency varchar(255),
    exchangeRate numeric(18, 5),
    date varchar(255)
 
);
"
Dim strPeriod As String = ""
Dim strCurrency As String = ""
Dim strPivot As String = ""
Dim strclo As Double = 0
Dim vavg As Double = 0
For Each row As DataRow In dt.Rows
strCurrency = row("fromCurrency")
' strclo = row("Value1")
vavg = row("exchangeRate")
strPeriod = row("Date")
Dim fxRatePkUsingNamesAvg As New FxRatePkUsingNames("exchangeRate", strPeriod, strCurrency, "EUR")
Dim objFxRateUsingNamesAvg As New FxRateUsingNames(fxRatePkUsingNamesAvg, vavg)
Dim objXFResultAvg As XFResult = BRApi.Finance.Data.SetFxRate(si, objFxRateUsingNamesAvg)
' Dim fxRatePkUsingNamesAmount As New FxRatePkUsingNames("ClosingRate", strPeriod, strCurrency, "EUR")
' Dim objFxRateUsingNamesAmount As New FxRateUsingNames(fxRatePkUsingNamesAmount, strclo)
'Dim objXFResult As XFResult = BRApi.Finance.Data.SetFxRate(si, objFxRateUsingNamesAmount)
' BRAPI.ErrorLog.LogMessage(si, "PBO objXFResult=" & objXFResult.Message)
' BRAPI.ErrorLog.LogMessage(si, "ClosingRate=  " & strclo)
BRAPI.ErrorLog.LogMessage(si, "exchangeRate=" & vavg)
BRAPI.ErrorLog.LogMessage(si, "Currency=" & strCurrency)
Next
Using dbconn As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
BRApi.Database.ExecuteActionQuery(dbconn, sSQL, False, True)
 
Using bulkCopy As New SqlBulkCopy(dbconn.ConnectionString)
bulkCopy.DestinationTableName = "Table_rate_mantu"
bulkCopy.WriteToServer(dt)
End Using
End Using
 
#End Region 

Do you have any idea why this is not working in OS ? 
Thanks
  • .net version changes with V8.

    Use Microsoft.Data.SqlClient instead of System.Data.SqlClient;

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    .net version changes with V8.

    Use Microsoft.Data.SqlClient instead of System.Data.SqlClient;

    • mtejjini's avatar
      mtejjini
      New Contributor III

      yes it did work with Microsoft.Data.SqlClient 
      Thanks for your help

       

       

  • mtejjini's avatar
    mtejjini
    New Contributor III

    already did it's still not working 😕 , thanks for your answer

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    The error tells us that the library for SqlBulkCopy is not in scope when running your code.  The runtime cannot find the SqlBulkCopy class to use it.  Thats why I suggested the import.

    Consider posting the complete rule in a code block so we can see what's going on.

     


    I wrote a rule similar to yours using SqlBulkCopy and its working for me.

  • mtejjini's avatar
    mtejjini
    New Contributor III

    Actually  the Library seems not to be complete in th Version 8.1.0
    when i try to import System.Data.SqlClient, no suggestion appears

    i don't know how can this be possible 😕