Connecting R with SQL Server

This post states the steps to connect R studio with SQL Server, so that we can directly access tables and can do analysis on data stored in SQL Server.

System Related Settings
1. Go to Control panel of your system.

2. Click on Administrative tools

Connecting R with SQL Server1

3. Select User dsn -> click on “add” -> “Sql server”

Connecting R with SQL Server2

4. Give the details as:

Connecting R with SQL Server3

5. Click on Next :

Connecting R with SQL Server4

Connecting R with SQL Server5

Open R studio
1. Install and load RODBC package:

Connecting R with SQL Server6

Connecting R with SQL Server7

2. Execute below Codes to connect R with SQL Server:
require(“RODBC”)
myconn <-odbcConnect("Roma", uid="*******", pwd="*******") pundat <- sqlQuery(myconn, "select top 2 * from Table_Trans_Currentweek")

3. While exit, close the connection as:
close(myconn)

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Roma

Leave a Reply

avatar
  Subscribe  
Notify of