When I upload this code to the web Shiny can't load it. When I enter Shiny it tells me the following error:
nanodbc/nanodbc.cpp:983: 00000: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source [unixODBC][FreeTDS][SQL Server]Unexpected EOF from the server [unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed
library(DBI)
library(odbc)
server = function(input, output, session) {
is_local = Sys.getenv('SHINY_PORT') == ""
server = "server"
database = "base"
uid = "login"
pwd = "pwd"
dbConnector <- function(server, database, uid, pwd,
local=TRUE, port=1433, tds_version=8.0,
Encrypt=yes, TrustServerCertificate=no){
if(local){
DBI::dbConnect(odbc::odbc(),
driver = "ODBC Driver 17 for SQL Server",
server = server,
database = database,
uid = uid,
pwd = pwd
)
}else{
DBI::dbConnect(odbc::odbc(),
driver = "FreeTDS",
server = server,
database = database,
uid = uid,
pwd = pwd,
port = port,
tds_version = tds_version
)
}
}
conn <- dbConnector(server, database, uid, pwd, is_local)
#Criando as tabelas dentro do servidor
df <- dbGetQuery(conn, 'SELECT * FROM TABLE')
)
Can someone help me?
Related
In Corda we are using CordaRPCClient to initiate transaction from the client. Here we are passing username and password to start the connection. Right now I am using hardcoded user name and password. Can I map this to a user table which is there in DB. Please share if there any best practices exists.
Yes you can definitely have rpc users fetched from a database. All you would need is some configuration in the nodes configuration file (node.conf).
The users are generally defined in the security block. Below is how it can be configured.
security = {
authService = {
dataSource = {
type = "DB"
passwordEncryption = "SHIRO_1_CRYPT"
connection = {
jdbcUrl = "<jdbc connection string>"
username = "<db username>"
password = "<db user password>"
driverClassName = "<JDBC driver>"
}
}
options = {
cache = {
expireAfterSecs = 120
maxEntries = 10000
}
}
}
You could find more details in our documentation here.
I am trying to send myself a test email from an AWS Virtual Machine (using an EC2 instance.)
My R code runs great, but I am now trying to send a test email to my email address using sendmailR.
I get the following error message:
Error in socketConnection(host = server, port = port, blocking = TRUE) :
cannot open the connection
In addition: Warning message:
In socketConnection(host = server, port = port, blocking = TRUE) :
localhost:25 cannot be opened
install.packages("sendmailR")
library(sendmailR)
sendmail(from = "XXXX#gmail.com",
to = "YYYY#gmail.com",
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 80 , user.name = "XXXX#gmail.com", passwd = "XXXX", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
Does anyone know how this is overcome?
protected void Update_Click(object sender, EventArgs e)
{
using (vhkEntities entities = vhkEntities.CreateEntitiesForSpecificDatabaseName("mysql"))
{
var empl = (from emp in entities.Employees where emp.EmpId == "1" select emp);
Employee obj = empl.Single();
obj.EmpId = "2";
obj.Name = "BBB";
int n = entities.SaveChanges();
}
public static vhkEntities CreateEntitiesForSpecificDatabaseName(string databaseName, bool contextOwnsConnection = true)
{
string sqlConnectionString = "";
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
if (databaseName == "mysql")
{
entityBuilder.Provider = "MySql.Data.MySqlClient";
sqlConnectionString = "server=localhost;user id=root;password=welcome#12;database=vhk;";
}
else
{
entityBuilder.Provider = "System.Data.SqlClient";
sqlConnectionString = "data source = DS-448A5BAEB93E; user id = sa; password = welcome#12; initial catalog = vhk;";
}
entityBuilder.ProviderConnectionString = sqlConnectionString;
//Set the Metadata location.
entityBuilder.Metadata = string.Format("res://{0}/EF.csdl|res://{0}/EF.ssdl|res://{0}/EF.msl",
typeof(vhkEntities).Assembly.FullName);
//Create entity connection
EntityConnection connection = new EntityConnection(entityBuilder.ConnectionString);
return new vhkEntities(connection);
}
I am trying to use Entity Framework to connect to both SQL Server and MySQL machines from my asp.net project. I have created one .edmx file for SQL Server database, so I want to use the same .edmx file to perform crud operations on both SQL Server and MySQL databases.
For insert operation it is working fine for both servers but coming to select operation I'm getting an error
Unable to cast object of type 'MySql.Data.MySqlClient.MySqlConnection' to type 'System.Data.SqlClient.SqlConnection'
Can anyone help me with this?
I had this problem but I didn't do anything special with the edmx files. I actually had to create a new solution and copy over my work to it because I couldn't get the config right in my existing solution. With my new solution first I connected to my the mssql server, and made sure that worked. Then I added all the latest version mysql nuget packages (MySql.Data, Mysql.Data.Entity, MySql.Fabric, and MySql.Web). I had separate projects in my solution for the data and the UI, so I needed to copy over some stuff from my data project's app.config to the UI project's web.config.
We have an Azure Scale Out resource, the problem is: For each instance, Hangfire launch a new server, any way to limit to one server only?
Assuming you are using Sql Server storage, which seems to be the case, you can do:
GlobalConfiguration.Configuration.UseSqlServerStorage("YourDB");
var servers = Hangfire.SqlServer.SqlServerStorage.Current
.GetMonitoringApi()
.Servers();
if (servers != null && servers.Count < 1)
//start new server here;
The workaround for this problem was: Check on SQLServer if there is an active Hangfire server:
using (var connection = new SqlConnection(myConnString))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT MAX(LastHeartBeat) FROM HangFire.Server";
connection.Open();
using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult))
{
if (reader.HasRows)
{
reader.Read();
DateTime lastBeat = reader.GetDateTime(0);
bool myResult = lastBeat >= DateTime.UtcNow.AddHours(-2);
}
}
}
Using httpuv package, Is there a way to restart server with given period?
Down there, I'm sharing my work as a possible answer.
Any further advice is welcome.
After some trial and error, here's a working code that restarts server every 5 seconds:
library(httpuv)
host <- '127.0.0.1'
port <- 8080
app <- list(
call = function(req) {
list(
status = 200L,
headers = list('Content-Type' = 'text/plain'),
body = 'Hello'
)
}
)
run <- function(host, port, app, period) {
sv <- startServer(host, port, app)
on.exit(stopServer(sv))
cat("Server started\n")
restart <- Sys.time() + period
while (TRUE) {
service()
Sys.sleep(0.001)
if (Sys.time() > restart) {
stopServer(sv)
sv <- startServer(host, port, app)
restart <- Sys.time() + period
cat("Server restarted\n")
}
}
}
run(host, port, app, 5)