SQL Server RODBC Connection

后端 未结 5 631
滥情空心
滥情空心 2020-11-28 03:10

Does anyone have a connection string example for using RODBC and connecting to MS SQL Server 2005 or 2008.

Thank you.

5条回答
  •  情歌与酒
    2020-11-28 03:49

    If you have to include the USERNAME and PASSWORD:

    library(RODBC) # don't forget to install it beforehand
    
    my_server="ABC05"
    my_db="myDatabaseName"
    my_username="JohnDoe"
    my_pwd="mVwpR55zobUldrdtXqeHez"
    
    
    db <- odbcDriverConnect(paste0("DRIVER={SQL Server};
                                     server=",my_server,";
                                     database=",my_db,";
                                     uid=",my_username,";
                                     pwd=",my_pwd))
    
    
    sql="SELECT * FROM dbo.MyTableName" #dbo is the schema here
    df <- sqlQuery(db,sql)
    

提交回复
热议问题