rodbc

Read data from several worksheets from workbook and eliminate comments

╄→尐↘猪︶ㄣ 提交于 2019-12-06 13:32:08
问题 I have workbooks with several (70+) worksheets. Each worksheet is a station name. Each worksheet has different number of comment line starting with # which I want to eliminate, then read the header from when the comments end and assign them to the column names. I was trying to use RODBC which works on a 32-bit machine/R/EXCEL but is not working on a 64-bit system. Below is what I have using RODBC. How can I do the same using XLconnect or something else for a 64-bit system? library(RODBC) ###

parlapply on sqlQuery from RODBC

こ雲淡風輕ζ 提交于 2019-12-06 10:01:28
问题 R Version : 2.14.1 x64 Running on Windows 7 Connecting to a database on a remote Microsoft SQL Server 2012 I have an unordered vectors of names, say: names<-c(“A”, “B”, “A”, “C”,”C”) each of which have an id in a table in my db. I need to convert the names to their corresponding ids. I currently have the following code to do it. ### names<-c(“A”, “B”, “A”, “C”,”C”) dbConn<-odbcDriverConnect(connection=”connection string”) #successfully connects nameToID<-function(name, dbConn){ #dbConn :

How do I install RODBC on Mac with unixodbc and freetds?

牧云@^-^@ 提交于 2019-12-06 06:55:38
问题 After a fairly extensive search, I noticed that a number of people are having a hard time finding a start-to-finish guide that answers this question. (At least one question notes that a solution exists, but the proposed solution does not get around the fact that, by default, RODBC attempts to compile against iODBC, which is not included with Yosemite.) I just went through this process, so I thought I would document it here in the hope that it will benefit others. I am connecting to a SQL

How to upload an image to SQL Server in R

落花浮王杯 提交于 2019-12-06 04:56:06
问题 I am creating some graphs which I want to update into a database table. The procedure I am following is: create the graphs as a png/jpeg file. Read that file as a binary vector sqlUpdate My code for steps 2 & 3: pngfile <- file(<filename>, "rb") N <- 1e6 repeat{ pngfilecontents <- readBin(pngfile, what="raw", n=N) if(length(pngfilecontents) == N) N <- 5 * N else break } close(pngfile) There is a table df_DemandPatternMaster in the database with primary key DemandPatternID, with appropriate

R- create temporary table in sql server from R data frame

独自空忆成欢 提交于 2019-12-06 01:31:35
问题 I know I can create a temporary table in SQL from R with, for example: require(RODBC) X<- odbcDriverConnect('driver={SQL Server}; server=s001000;database=X1;trusted_connection=true') sqlQuery(X, "create table #temptable (test int)" ) sqlQuery(X, "insert into #temptable(test) values(201508)") doesItWork <- sqlQuery(X, "select * from #temptable") But I would like to create a temporary table in sql server from an R object (I have a table that has the result of previous R calculations and I need

How to manage a database connection in an R Package

£可爱£侵袭症+ 提交于 2019-12-06 01:10:55
问题 I'm building an R package, the main purpose of which is to abstract away the pain of dealing with a proprietary database that requires some fairly complex SQL queries in order get data out. As such, the connection to the Microsoft SQL Server (obtained by odbcDriverConnect ) is a constant and important part of this package, but I can't work out how best to manage this and I'm hoping for advice as to how this should be implemented in R. My current thoughts are: Make the user ensure they have a

Data from ODBC blob not matching return from SQL query

▼魔方 西西 提交于 2019-12-06 00:06:22
I’m reading a BLOB field from an ODBC data connection (the BLOB field is a file). I connect and query the database, returning the blob and the filename. The blob itself does not contain the same data as I find in the database however. My code is as follows along with the data returned vs in the DB. library(RODBC) sqlret<-odbcConnect('ODBCConnection') qry<-'select content,Filename from document with(nolock) where documentid = \'xxxx\'' df<-sqlQuery(sqlret,qry) close(sqlret) rootpath<-paste0(getwd(),'/DocTest/') dir.create(rootpath,showWarnings = FALSE) content<-unlist(df$content) fileout<-file

RODBC connectivity to Oracle without tnsnames.ora

大憨熊 提交于 2019-12-05 23:07:55
I am trying to connect to Oracle from R using RODBC without using tnsnanes.ora. I have tried following strings, but none of them are working. > con.text <- paste0("Driver={OracleODBC-11g};Dbq=//oracle.server:1527/database.pdw.prod;Uid=user;Pwd=pswd;") > con.text <- paste0("Driver={OracleODBC-11g}; ", "CONNECTSTRING=(DESCRIPTION=(ADDRESS= (PROTOCOL = TCP)(HOST = oracle.server)(PORT = 1527))(CONNECT_DATA=(SERVICE_NAME = database.pdw.prod))); uid=user;pwd=pswd;") > con.text <- paste0("Driver=", "OracleODBC-11g" , ";Server=", "oracle.server" , ";Database=", "database.pdw.prod" , ";Uid=", "user" ,

How do I connect to an SQL server database in R

我们两清 提交于 2019-12-05 15:06:29
I'm trying to connect to the SQL Sever database using R but not sure on the details for the query string. I normally use SQL server management studio on SQL Server 2008 and connnect using single sign on. I found the below example myconn <- odbcDriverConnect(connection="Driver={SQL Server Native Client 11.0};server=hostname;database=TPCH; trusted_connection=yes;") I get the below warning message Warning messages: 1: In odbcDriverConnect(connection = "Driver={SQL Server \nNative Client 11.0};server=hostname;database=TPCH;\ntrusted_connection=yes;") : [RODBC] ERROR: state IM002, code 0, message

Unable to append to SQL Server table using sqlSave in R

[亡魂溺海] 提交于 2019-12-05 09:48:36
I am trying to update a SQL table using sqlSave function of RODBC package in R. Data is present in a data frame. When I try to run the command: sqlSave(DBConn, dat=df, verbose=T, tablename='table', append=T) I get the following error: Query: INSERT INTO "table" ( "col1", "col2", "col3", "col4" ) VALUES ( ?,?,?,?,? ) sqlwrite returned 42000 -131 [Sybase][ODBC Driver][Sybase IQ]Syntax error near 'table' on line 1 [RODBC] ERROR: Could not SQLPrepare 'INSERT INTO "table" ( "col1", "col2", "col3", "col4" ) VALUES ( ?,?,?,?,? )' What am I doing wrong here so that I am not getting the values in