How to access a database file .MDF from R - sql-server

I am trying to connect to the AdventureWorks2012 database (MDF file) from R. The file is stored on my local computer. I have been able to setup SQl Server and the SQL Server Management Studio.
In Server Management Studio I have my PC name (2NDHANDBRUTUS) as the server and I can find AdventureWorks2012 :
However, I am not able to connect to it via R through the odbcConnect() statements. I have setup the following datasource:\
I have tried the following R command:
CON <- odbcConnect('AdventureWorks2012', uid = 'Rob Oudehand', pwd = 'Hondenmand5')
And I receive this error:
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=AdventureWorks2012;UID=Rob Oudehand;PWD=Hondenmand5") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In RODBC::odbcDriverConnect("DSN=AdventureWorks2012;UID=Rob Oudehand;PWD=Hondenmand5") :
ODBC connection failed
Can someone assist me in how I should access such a MDF-file from R? Should it be done via SQl Server via ODBSConnect, or is there another way?

Related

How to create target connection to load data from SQL Server to MS Access 2016 in Informatica Powercenter?

My goal is to load data from SQL Server to MS Access table.
Informatica Server is - Red Hat Enterprise Linux 7.3
Informatica Version is - 10.2.0 Hotfix 1
MS Access Version - 2016
MS Access file location - Windows
Reading from SQL Server is no issue, but I am not able to figure out how to connect to MS Access database file that is in my local windows directory.
I created an ODBC connection in workflow manager and used dummy username and password. I am not sure if I have to use dummy credentials here either.
ODBC connection in Informatica
I created DSN in my local computer. Using the DSN, I was able to create Informatica target in mapping designer.
ODBC DSN
MS Target in Designer
When I run the wf, I get the below error. I probably need to update the ODBC.ini file in my informatica server. But I don't know what details I could use there e.g. which driver to use or other fields.
Workflow Error
Error code: -
CMN_1022 [
[DataDirect][ODBC lib] Driver Manager Message file not found. Please check for the value of InstallDir in your odbc.ini.
Database driver error...
Function Name : Connect
Database driver error...
Function Name : Connect
Database Error: Failed to connect to database using user [test] and connection string [IFRSXTRACT].]
Can someone guide me if there are any other steps to establish connection to MS Access.

Create Database link to MS SQL Server on Oracle database

Please help.. I need to connect to a SQL Server database (B) from an Oracle database (A) which are both on Windows server machines. Here is what I did.
System DS created on (A):-
Name: ISECWM
Driver: ODBC Driver 11 for SQL Server
Test Results:
Microsoft ODBC Driver for SQL Server Version 12.00.5543
Running connectivity tests...
Attempting connection Connection established Verifying option settings
Disconnecting from server
TESTS COMPLETED SUCCESSFULLY!
$ORACLE_HOME/hs/admin/initISECWM.ora file contains
HS_FDS_CONNECT_INFO = ISECWM
HS_FDS_TRACE_LEVEL = OFF
$ORACLE_HOME/network/admin/listener.ora updated:-
SID_LIST_LISTENER = (SID_LIST = (SID_DESC =
(SID_NAME=ISECWM)
(ORACLE_HOME=c:\oracle\11g)
(PROGRAM=dg4odbc)
) )
$ORACLE_HOME/network/admin/tnsnames.ora updated:-
WORLDMAP.DBL = (DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=SERVER A HOSTNAME)(PORT=1521))
(CONNECT_DATA=(SID=ISECWM)) (HS=OK) )
Database link created:-
CREATE PUBLIC DATABASE LINK TSTDBLINK CONNECT TO "sql server
username" IDENTIFIED BY "sql server password" USING 'WORLDMAP.DBL';
Tested the database link with:-
select * from dual#TSTDBLINK; --gives the error
Error:-
ORA-28513: internal error in heterogeneous remote agent ORA-02063:
preceding line from TSTDBLINK
28513. 00000 - "internal error in heterogeneous remote agent"
*Cause: An internal error has occurred in the Oracle remote agent
supporting a heterogeneous database link.
*Action: Make a note of how the error was produced and contact the
customer support representative of the agent vendor. Error at Line: 7 Column: 20
Ah, finally Oracle helped me with the issue.
It seems I had 2 homes, I put the initISECWM.ora in the wrong Oracle home.
Just copied and pasted it in the other home/hs/admin/ and it worked like a wonder! Voila!

R RODBC SQL Server Connection

I use windows authentication to connect to sql server. And I'm trying to connect to the sql server table in R. But R is not connecting to the database. I also tried typing in my windows login for uid and pwd. still no luck.
library(RODBC)
driver.name <- "SQL Server"
db.name <- "dw-xxx"
host.name <- "xx-xxx"
port <-"xxxx"
server.name <-"dw-xx"
con.text <- paste("DRIVER=",driver.name,
";Database=",db.name,
";Server=",server.name,
";Port=",port,
";PROTOCOL=TCPIP",
";trusted_connection=true",
sep="")
con1 <- odbcDriverConnect(con.text)
Warning messages:
1: In odbcDriverConnect(con.text) :
[RODBC] ERROR: state 42000, code 4060, message [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "dw-xxx" requested by the login. The login failed.
2: In odbcDriverConnect(con.text) :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute
3: In odbcDriverConnect(con.text) : ODBC connection failed
> odbcGetInfo(con1)
Error in odbcGetInfo(con1) : argument is not an open RODBC channel
RStudio : Version 1.0.153
Microsoft SQL Server Management Studio 14.0.17177.0
I got this same problem. Apparantly the PORT format was not accepted. It was working when I moved the port to the server part likes this (giving SERVER=server,port):
con.text <- paste("DRIVER={",driver.name,"}",
";Database=",db.name,
";Server=",server.name,
",",port
";PROTOCOL=TCPIP",
";trusted_connection=true",
sep="")

Inserting using clause location in Sybase IQ

I'm using Sybase IQ 16 and I'm trying to insert data from a Sybase ASE 15.7
I defined an ODBC dsn for Sybase ASE and the connection test is positive,
the name of the DSN is EMS_SERVER_ems, this dsn is defined on database ems,
I created the server within Sybase IQ using the command create server:
create server EMS_SERVER
CLASS 'aseodbc'
using 'DRIVER=Adaptive Server Enterprise;dsn=EMS_SERVER_ems';
I also created the external login
create externlogin DBA to EMS_SERVER
REMOTE LOGIN DBA identified by sql
but when I'm trying the command :
insert MyFirstIqTable
location 'EMS_SERVER.ems' {select * from my_table}
then I get the error :
Could not execute statement.
CtLibrary Error: 44, Severity: 0, Origin: 1, Layer: 4
Error Message:
ct_connect(): protocol specific layer: external error: The attempt to connect to the server failed.
OS Error: 0, OS Message:
(hqmlib\hqm_con.cxx 199)
SQLCODE=-1003002, ODBC 3 State="HY000"
Does someone has an idea ?
Got it, this was because my external login was wrongly defined.
It's working like a charm !

unable to connect to azure vm database from R

I am trying to connect to a Microsoft SQL Server database running on a virtual machine in Microsoft Azure, from R.
Here is what my SQL server looks like
This is my connection string
library(RODBC)
channel = odbcConnect(dsn="something.cloudapp.net",uid="myusername",pwd="mypassword");
However, I keep getting this error
Warning messages:
1: In odbcDriverConnect("DSN=servername.cloudapp.net,1433;UID=myusername;PWD=mypassword") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("DSN=servername.cloudapp.net,1433;UID=myusername;PWD=mypassword"):
ODBC connection failed
Why do I keep getting this error?
Try using the more flexible odbcDriverConnect function like this:
odbcDriverConnect('driver={SQL Server};Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;')
Here it is with carriage returns for readability:
odbcDriverConnect(
'driver={SQL Server};
Server=myServerAddress;
Database=myDataBase;
User Id=myUsername;
Password=myPassword;')
See also:
SQL Server RODBC Connection
http://www.connectionstrings.com/sql-server/
http://www.inside-r.org/packages/cran/rodbc/docs/odbcConnect

Resources