RODBC odbcDriverConnect() Connection Error

前端 未结 4 1608
长发绾君心
长发绾君心 2020-11-27 17:09

I\'m trying to use

odbcDriverConnect(\'driver={SQL Server};server=servername\\instancename,port;database=testing;username=abc;password=123456\') 

4条回答
  •  死守一世寂寞
    2020-11-27 17:53

    1.Connet to MySQL

    a)if Mysql is installed in your system, if not install it.

    b)download the RMySQL IN R

    library(RMySQL)

    drv = dbDriver("MySQL 5.0.1")

    make sure MySQL version is correct.

    con = dbConnect(drv,host="localhost",dbname="test",user="root",pass="root")

    use local host or use the server i.e ip address

    use the required database name, user name and password

    album = dbGetQuery(con,statement="select * from table")

    run required query

    close(con)

    2.Another way to connect database

    a)first install any database like MySQL,Oracle,SQL Server

    b)install the ODBC connector for database

    library(Rodbc)

    channel <- odbcConnect("test", uid="ripley", pwd="secret")

    test is the connection name of odbc conector which user has to set manualy

    user can find this in Administrator tool

    res <- sqlFetch(ch, "table name")

    A table can be retrieved as a data frame

    res<-sqlQuery(channel, paste("select query"))

    part of the with condition one table can be retrieved as a data frame

    sqlSave(channel, dataframe)

    to save a dataframe to the database(dont use "res<-" something like this)

    like user can use

    sqlCopy() sqlDrop()

    sqlTables()

    close(channel)

    always close the connection

提交回复
热议问题