RPostgreSQL cannot connect to the server - sql

I'm trying to access a PostgreSQL database through R.
I tried the following code:
library(RPostgreSQL)
library(DBI)
drv <- dbDriver("PostgreSQL")
con = dbConnect(drv, #constructs SQL driver
host = MyHost,
port = MyPort,
dbname = MyDbname,
user = MyUser,
password = pw)
I already have PostgreSQL installed on my computer.
With all my credentials being correct, I still get this Error:
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect [MyUser]#[MyHost] on MyDbname
any ideas what causes the problem? The same problem here has no solution yet. Thanks for your help
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
Kasia

At the end, I managed to connect to the database with RPosgres package
install.packages("devtools") and load them
devtools::install_github("RcppCore/Rcpp")
devtools::install_github("rstats-db/DBI")
devtools::install_github("rstats-db/RPostgres")
con <- dbConnect(RPostgres::Postgres(),
host = MyHost,
port = MyPort,
dbname = MyDbname,
user = MyUser,
password = pw)
res <- dbSendQuery(con, "SELECT * FROM orders LIMIT 10")
dbFetch(res)
dbClearResult(res)

Related

Connecting mariaDB on Digital Ocean using R Studio

I installed mariaDB on digital ocean. I set up user name and password. Now, I am trying to connect it through R studio. But, it is not working.
Code I used.
library(odbc)
library("RMariaDB")
con <- dbConnect(odbc(),
Driver = "MariaDB ODBC 3.1 Driver",
Server = "206.189.---.", #droplet IP
Database = "test",
Username = "root",
Password = " ****"
Trusted_Connection = "True")
Error I got :
Error: nanodbc/nanodbc.cpp:983: HY000: [ma-3.1.7]Can't connect to MySQL server on '206.189.---.--' (10061)
I installed a connection driver on my windows before running these codes on R Studio. What am I missing here?

Airflow Adaptive Server connection failed

I want to connect my Airflow and Microsoft SQL Server. I configured my connection under 'connections' bar in 'Admin' box as mentioned in the following link:
http://airflow.apache.org/howto/manage-connections.html
But when I run my Dag task that is related to SQL server immedatly fails by following error:
[2019-03-28 16:16:07,439] {models.py:1788} ERROR - (18456, "Login failed for user 'XXXX'.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (***.***.***.28:1433)\n")
My code from DAG for Micrososft Sql Connection is following:
sql_command = """
select * from [sys].[tables]
"""
t3 = MsSqlOperator( task_id = 'run_test_proc',
mssql_conn_id = 'FIConnection',
sql = sql_command,
dag = dag)
I verified ip address and port number kind of configuration things by establishing connection through pymssql library from my local computer. Test code is following:
pymssql.connect(server="***.***.***.28:1433",
user="XXXX",
password="XXXXXX"
) as conn:
df = pd.read_sql("SELECT * FROM [sys].[tables]", conn)
print(df)
Could you please share if you have experienced this issue?
By the way I am using VirtualBox in Ubuntu 16.04 LTS
I had the same problem because freetds-dev was missing on linux:
apt-get install freetds-dev

Airbnb Superset Datasource Configuration for SparkSQL

I am using Spark 1.6.2 (from the Datastax Enterprise Edition => DSE 5.0.4) and Python 2.7 When I give
from impala.dbapi import connect
Conn = connect (host = '172.31.12.201', port = 7077, user = 'xxxx', password = 'xxxx1111', database = 'test_database', auth_mechanism = 'PLAIN')
it just hangs and never comes out spark master runs at 172.31.12.201 on port 7077
My configuration in superset is as below
SQLAlchemy URI => impala://172.31.12.201:7077/test_database
Extra => {
"metadata_params": {},
"engine_params": {"connect_args": {"user": "xxxx", "password": "xxxx1111"}} }
I had to start dse spark thrift server as below
dse -u <username> -p <password> spark-sql-thriftserver start
This will start the hive server in DSE cluster on port 10000

how to connect to wamp server from another computer/different pc

I have created an application in VB. I have successfully connected the application to wamp localhost (same computer). But I can't connect it from another computer that is in the same network. Please help me to connect...
here is my code:
Dim server1 As String
Dim client1 As String
Dim cmd As New Odbc.OdbcCommand
server1 = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=db_checkvoucher;User=root;Password=;Option=3;"
client1 = "Driver={MySQL ODBC 5.1 Driver};server=192.168.1.2;" _
& "User=root;Password=;" _
& "database=db_checkvoucher;"
If Form1.TextBox1.Text = "1" Then
con.ConnectionString = client1
Else
con.ConnectionString = server1
End If
cmd.Connection = New Odbc.OdbcConnection(con.ConnectionString)
con.Open()
I am getting this error:
ERROR [HY000] [MySQL][ODBC 5.1 Driver]Can't connect to MySQL server on '192.168.1.2' (10060) ERROR [HY000] [MySQL][ODBC 5.1 Driver]Can't connect to MySQL server on '192.168.1.2' (10060)
I have already run wamp server on the server computer.
It's probably an issue with your firewall on the server.
See here for notes on how to allow mysql connections. http://portforward.com/english/routers/firewalling/Microsoft/WindowsXPFirewallFirewall/MySQL_Server.htm

What would be a connection string for Ironpython to connect to a SQL Server CE?

I'm working with Visual Studio to connect to an IronPython application to a local .sdf database. However, I get this error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Here's my code:
import wpf
import os
import ConfigParser
import clr
clr.AddReference('System.Data')
from System.Data.SqlClient import SqlConnection, SqlParameter
...
conn_string = "Data Source=" + AppData + "local.static.sdf;Password=[PASSWORD];Persist Security Info=True"
connection = SqlConnection(conn_string)
connection.Open()
command = connection.CreateCommand()
command.CommandText = 'select nom from employee where id = #id'
command.Parameters.Add(SqlParameter('id', 1))
reader = command.ExecuteReader()
buff = ''
while reader.Read():
buff = reader['id']
print buff
connection.Close()
Anyone has an idea about what is going wrong with this piece of code?
Thank you!
~Stéphane
Interesting scenario, wonder if you can make it work...
You need
clr.AddReference('System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91')
and
from System.Data.SqlServerCe import SqlCeConnection, SqlCeParameter