Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I am trying to insert the dataset that I am receiving from another source into a SQL Server. As there is no option of doing this is native Power BI, I am using R functions to do this. Here is the code that I have:
library(RODBC);
serverConn <- odbcDriverConnect(connection="Driver={SQL Server Native Client 11.0};server=<Server>;database=<Database>;trusted_connection=yes;");
sqlSave(serverConn, dataset, tablename ="<tableName>",rownames=FALSE, append = TRUE)
When I run this script after loading the dataset, I am getting the below error:
DataSource.Error: ADO.NET: R script error.
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in 'data'
Calls: sqlSave -> sqlwrite -> odbcUpdate
Execution halted
Warning message:
closing unused RODBC handle 1
Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error.
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in 'data'
Calls: sqlSave -> sqlwrite -> odbcUpdate
Execution halted
Warning message:
closing unused RODBC handle 1
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Radio.RScriptRuntimeExceptionThis error is coming at line 3. I have uncommented it and ran the step and it was working fine. Any idea why this is happening? This same code is running fine when I run it from R console.
Solved! Go to Solution.
Figured it out. It was due to mismatch in the names of the columns. My dataframe has columns A and B but my table has columns C and B. Modified the columns to match the names and then it worked.
Figured it out. It was due to mismatch in the names of the columns. My dataframe has columns A and B but my table has columns C and B. Modified the columns to match the names and then it worked.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 35 | |
| 34 | |
| 31 | |
| 27 |
| User | Count |
|---|---|
| 135 | |
| 102 | |
| 67 | |
| 65 | |
| 56 |