问题
I'm trying to implement a r script within power bi to update a SQL Server database. I keep running into this problem... anyone know how I can resolve the error?
library(RODBC)
outputframe=data.frame(dataset)
DBHANDLE<-odbcDriverConnect('driver={SQL Server};server=____;database=___;trusted_connection=true')
TBLExist="sbs.Iterations" %in% sqlTables(DBHANDLE)$TABLE_NAME
if (!TBLExist)
sqlSave(DBHANDLE, data.frame(dataset), tablename = "sbs.Iterations",rownames=FALSE, append = FALSE)
DataSource.Error: ADO.NET: R script error. During startup - Warning message: In setJsonDatabasePath(system.file("extdata/capabilities.json", : bytecode version mismatch; using eval Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, numerals = numerals, : invalid input '[Adhoc] [C2R]:When user clicks on 🙂(Provide feedback) from Main UI, User is not able to see submit button.' in 'utf8towcs' Calls: read.csv -> read.table -> type.convert Execution halted Details: DataSourceKind=R DataSourcePath=R Message=R script error. During startup - Warning message: In setJsonDatabasePath(system.file("extdata/capabilities.json", : bytecode version mismatch; using eval Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, numerals = numerals, : invalid input '[Adhoc] [C2R]:When user clicks on 🙂(Provide feedback) from Main UI, User is not able to see submit button.' in 'utf8towcs' Calls: read.csv -> read.table -> type.convert Execution halted ErrorCode=-2147467259 ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException
回答1:
Does this work for you?
library(RODBC)
dbconnection <- odbcDriverConnect("Driver=ODBC Driver 11 for SQL Server;Server=Server_Name; Database=DB_Name;Uid=; Pwd=; trusted_connection=yes")
initdata <- sqlQuery(dbconnection,paste("select * from MyTable;"))
odbcClose(channel)
Make sure your driver version matches whatever you have installed on your machine.
回答2:
Try casting all of the CHAR
and/or VARCHAR
data types in your source query to NCHAR
and NVARCHAR
respectively. If your source data contains any characters with ASCII character codes of 128 or above (and in particular, 192 or above), you may encounter the "bytecode version mismatch" error.
Some additional reading here: sp_execute_external_script and Bytecode Version Mismatch
来源:https://stackoverflow.com/questions/57618108/trying-to-implement-a-r-script-within-power-bi-to-update-a-sql-server-database