rodbc

RODBC functions and errors/warnings

Deadly 提交于 2019-12-30 11:02:52
问题 A question about this R code: library(RODBC) ch <- tryCatch(odbcConnect("RTEST"), warning=function(w){print("FAIL! (warning)");return(NA)}, error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)}) df <- tryCatch(sqlQuery(ch,"SELECT Test from tblTest"), warning=function(w){print("FAIL! (warning)");return(NA)}, error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)}) odbcClose(ch) Code works fine for errors (forced by omitting the required paramaters in the code) in

RODBC functions and errors/warnings

徘徊边缘 提交于 2019-12-30 11:02:39
问题 A question about this R code: library(RODBC) ch <- tryCatch(odbcConnect("RTEST"), warning=function(w){print("FAIL! (warning)");return(NA)}, error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)}) df <- tryCatch(sqlQuery(ch,"SELECT Test from tblTest"), warning=function(w){print("FAIL! (warning)");return(NA)}, error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)}) odbcClose(ch) Code works fine for errors (forced by omitting the required paramaters in the code) in

sqlSave: Mapping dataframe timestamps to SQL Server timestamps

一曲冷凌霜 提交于 2019-12-30 04:00:09
问题 I am trying to upload a data frame to a table in sql server using sqlSave(). This dataframe has a timestamp in it and I'd like to map the timestamp col to a datetime col in sqlserver. I am getting two problems. 1. It maps the data frame's timestamp to a float. 2. It creates a table, but no data is uploaded and I get an error. Here's an example data frame, mdf: mdf <- structure(list(run = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("run_00", "run_01", "run_02", "run_03", "run_04"), class =

How to write a parameterized SQL query?

泪湿孤枕 提交于 2019-12-25 01:25:54
问题 I am trying this query to fetch my value from a MS SQL database on basis of two conditions but still I am getting exception in the syntax part. Can anybody tell me what is the correct way to write a parameterized query in R? Following is the query I used: query<- paste0("SELECT [value] FROM [RiskDashboard].[dbo].[tbl_Simulation] where Row_Id=", row_id[c(1),] ," AND Script_Id=", script_id[c(1),] ,) T_data<-sqlQuery(ch,query) print(T_data) 回答1: Parameterizing data is very important - especially

SQL Server procedure that did not complete when it executed from R

穿精又带淫゛_ 提交于 2019-12-24 20:06:02
问题 When I ran a procedure from R, it stops in the middle of the execution. But if I ran it directly from SQL Server, it completes the execution. Here is the code (there is not a lot to show): connection<-odbcDriverConnect("SERVER=server_name;DRIVER={SQL Server};DATABASE=DB;UID=RUser;PWD=****") stringEXEC<-"EXEC [dbo].[LongProcedure]" data<-sqlQuery(channel = connection,query = stringEXEC,errors = TRUE) Some remarks: the procedure is calling for 12 another procedures. and each of the 12 creating

Connect to ORACLE via R, using the info in sql developer

烈酒焚心 提交于 2019-12-24 19:54:14
问题 I am working on a machine without admin rights. I use sql developer to connect to an internal database. I would like to connect via R also. Is there any way I can do this, without admin rights? Some solutions require me to set up a systemDNS - which I can not do. Other requires me to install jvm.dll My environment: Windows7, sqldeveloper, connection method is via TNS file. 回答1: Connecting to SQL Developer via R is far more difficult than other databases I've encountered. It's important that

R data frame to Oracle SQL table: Could not allocate memory

孤街醉人 提交于 2019-12-24 08:55:19
问题 I want to insert a data frame from R into an existing table in my Oracle database using this code: sqlSave(connection, df, tablename = "oracle_table", append = TRUE) I get the error could not allocate memory . I tried inserting only one line, but the error still showed up. The type of some fields in the Oracle target table are memo . How can I insert my df in the oracle table? Structure of R data frame: $a: num $b: chr Structure of target table in Oracle database: a: number(10,0) b: CLOB

R data frame to Oracle SQL table: Could not allocate memory

左心房为你撑大大i 提交于 2019-12-24 08:52:19
问题 I want to insert a data frame from R into an existing table in my Oracle database using this code: sqlSave(connection, df, tablename = "oracle_table", append = TRUE) I get the error could not allocate memory . I tried inserting only one line, but the error still showed up. The type of some fields in the Oracle target table are memo . How can I insert my df in the oracle table? Structure of R data frame: $a: num $b: chr Structure of target table in Oracle database: a: number(10,0) b: CLOB

R RODBC sqlSave crashing/disconnecting when too many columns supplied to existing table

落花浮王杯 提交于 2019-12-24 02:58:07
问题 I've found a situation where R hangs due to sqlSave not handling cases where the are more columns being inserted than are present in the table. Does anyone have any insight on how I can resolve this behaviour? I had the idea of retrieving the number of columns already in the table but this would be a siginificant performance drain and add significant complexity to the code. The error (reproduction will require a dsn/database connection locally) channel <- odbcConnect("mydb") odbcClearError

Connecting 32-bit R to a 32-bit Access database

丶灬走出姿态 提交于 2019-12-24 02:05:17
问题 I am using 32-bit R with RStudio to try and connect to an .accdb file. I have 32-bit MS Access running on my machine. R version: platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status major 3 minor 1.2 ... language R version.string R version 3.1.2 (2014-10-31) nickname Pumpkin Helmet I'm trying to use the RODBC package to connect to an MS Access database. I cannot use odbcConnectAccess("location_of_database.accdb") to connect to a database provided by a client. This