Skip to main content
Member
May 2, 2024 12:22 PM UTC
Solved

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
RobbSalzmann
Employee - Advisor
May 2, 2024 2:13 PM UTC

.net version changes with V8.

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

6 replies

RobbSalzmann
Employee - Advisor
Employee - Advisor
May 2, 2024 12:33 PM UTC

Try adding 

Imports System.Data.SqlClient

 

mtejjiniAuthor
Member
May 2, 2024 12:35 PM UTC

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

RobbSalzmann
Employee - Advisor
Employee - Advisor
May 2, 2024 1:29 PM UTC

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.

RobbSalzmann_0-1714656654198.png

 


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

mtejjiniAuthor
Member
May 2, 2024 2:02 PM UTC

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

mtejjini_0-1714658544161.png

i don't know how can this be possible 😕



RobbSalzmann
Employee - Advisor
Employee - Advisor
May 2, 2024 2:13 PM UTC

.net version changes with V8.

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

mtejjiniAuthor
Member
May 2, 2024 2:24 PM UTC

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