Google apps script connection problem with SQL Server - javascript

I have a problem in Google apps script connecting to a SQL Server database. Here is the code:
//Function to connect to ms sql server
function conn_test_server(){
var conn = Jdbc.getConnection("jdbc:sqlserver:\\ipaddress\instance:port",
"username", "password!");
}
//String formats i have used
//"jdbc:sqlserver://ipaddress:port/database"
//"jdbc:sqlserver:\\ipaddress\instance:port"
When I tried it an error is thrown that tells my to check the connection string, username and password.
I have triple checked them, as well the port seems open as I can connect through another app and also have whitelist the required IP's so the firewall does not stop them to connecting.
Please, if you could tell me other things I can look into to solve this error I would be very grateful.

Related

NodeJS oracledb - ORA-03135: connection lost contact

I have a NodeJS application which uses oracledb library to connect to an Oracle Database . It's using the following code to try to connect to the database:
this.oracledb.fetchAsBuffer = [this.oracledb.BLOB];
const dbconfig = {
user: 'mysuser',
password: 'mypass',
connectString: '10.xxx.xx.xxx/MYORCLID'
};
console.log("Trying to get connection");
return await this.oracledb.getConnection(dbconfig);
But, I'm receiving the following error now during the "getConnection" method:
"Error: ORA-03135: connection lost contact"
Please, is there anything wrong with this code? It was working before but suddenly I started to receive the above message. From where should I start to check?
I've tried telnet and it worked too, so I'm not sure if this is a firewall issue.
I managed to solve the issue.
It was an internal blocking issue inside our network. They use a type of application which checks the origin hostname, linux user, application name and other properties before allowing access to the database.
After talking to my Infra and DB Team, they checked and liberated the access, and then everything worked as it should.
Thanks!

cannot open MSSQL database in c#

I've a local html page that I'm working on. It's mostly HTML and Javascript and some aspx c#.
Whenever I am trying open the database, I get error:
System.Data.SqlClient.SqlException: Cannot open database "Database.mdf" requested by the login. The login failed.
Login failed for user 'ROYI\user'.
I searched a bit on the internet, and I've learned that this uses the windows authentication but it doesn't seem to work. I don't have a password for this db, so why can't it connect?
My connection string is:
"Server= localhost; Database=Database.mdf; Integrated Security = SSPI; ";
When I do:
SqlConnection conn = new SqlConnection(connString);
conn.Open();
I get the error on conn.open();.
Where is the problem with my connection string?

Why does MySQL connection string work in bash but not javascript?

I've setup a physical mac computer to be a MySQL server. It works perfectly well if I access it remotely on the internet if I access it through the Terminal. Edit: I now realise this is on the local network only. So I'm now setting up a static IP and will have to post another question on that if I get stuck
But I'd love to solve why it someone doesn't work if I connect with javascript, such as in GoogleSpreadsheets or any related add-ons in GoogleSpreadsheets (which are also written on Javascript I think).
I can use any of those javascript approaches to connect to other databases which I have access to, but I'd like to find out why I can't connect to mine in particular and if there is anything I can change? Thanks.
I setup a MySQL server on computer A (Mac OS X Yosemite). I can connect fine if I use do the following in bash on computer B (Mac OS El Capitan) and then get whatever output I need from MySQL.
$ # in bash, change path to ensure SQL runs
$ export PATH=$PATH:/usr/local/mysql/bin/
$ # start sql and run a query
$ mysql -u test -pXXXXX -h 192.168.XXX.XX sakila # replace X's with real credentials, where -p is for the password and -h is for the IP address.
$ mysql> SHOW TABLES;
$ mysql> #... output is good
$ mysql> exit;
$
If I run the same credentials in Google Spreadsheets script editor, I get an error on the last line saying that either my connection string, user or password are not correct. See script below.
// attempt to access SQL data using javascript on https://script.google.com
function Drive() {
var ServerIP = '192.168.XXX.XX'; // IP address of the server. replace with real IP
var SQL_Port = '3306'; // port number
var SQL_Usr = 'test'; // name of user
var SQL_Pwd = 'xxxxx'; // password of user. replace with real password
var SQL_DB = 'sakila'; // name of sample database downloaded from MySQL Workbench documentation.
var connectorInstance = 'jdbc:mysql://' + ServerIP +':' + SQL_Port;
var ConnectString = connectorInstance + '/' + SQL_DB;
var conn = Jdbc.getConnection(ConnectString, SQL_Usr, SQL_Pwd); // error on this line
}
My javascript, my syntax is definitely correct, since if I swop in the credentials for another online database then the error disappears. Similarly, I tried 4 different Google Spreadsheets add-ons which are available when you search "SQL" in the add-on store; those work with all databases I tried but not my own.
And my own server's credentials and authorisation should be working correctly, since I can connect using bash as shown at the top.
Is there some security option setup on the other databases in the server or in their internet connection which means javascript will connect on theirs and not mine? Is there something I missed?
My alternatives would be to only access the server with bash (not good when I am building a Spreadsheet-based front-end), or to host the server online, which would involve some costs.
Would an SSH connection help at all? I haven't used one before. Any help would be appreciated.
Steps I've tried
I started off setting up MySQL Workbench with a config file as -"etc/my.cnf".
I set "skip-networking" off.
I made sure "bind_address" was off and also tried variations since as "0.0.0.0", "*" and "%".
I followed a lesson on setting up javascript code for Google scripts and granted sufficent user account details on location "%" (yes I know that's not secure but this is a small test db).
I've tried playing around with other Options File preferences under Networking or other section, but they either have no effect or the server fails to restart successfully with those applied.
Before testing my DB connection, I make sure I restart my SQL server to ensure option and user changes are applied.
I've checked StackOverflow to see who else is asking about remote databases, javascript or connection strings. No one else seems to have my exact issue.
I've tried using the host's name "Servers-Macbook-Air.local" in place of IP, again that works in bash but NOT in Javascript still. Also if I use IP or hostname for another database, that works.
I did some research after Hardy's comment - I think it is the private IP restricting me. I had only tried with both laptops in Wifi range.
http://www.gohacking.com/private-and-public-ip-addresses/
Say for example, if a network X consists of 10 computers, each of them can be given an IP starting from 192.168.1.1 to 192.168.1.10. Unlike the public IP, the administrator of the private network is free to assign an IP address of his own choice (provided the IP number falls in the private IP address range as mentioned above).
Devices with private IP addresses cannot connect directly to the Internet. Likewise, computers outside the local network cannot connect directly to a device with a private IP.
Your problem is you are trying to your local IP address of 192.168.xxx.xxx
You can not do that from the internet. As a matter of fact, that IP address only exists within your network. You and I could both have the IP of 192.168.1.10. Most off-the-shelf routers create networks that begin with 192.168.1.1 (which is probably where you can access your firewall).
The only way this could work is if you used your public IP address and you have the port you are looking for configured to point to your machine. This would typically require some Port Forwarding or Firewall configuration.
You can check your public IP with sites like http://www.ipchicken.com

Issues connecting to Amazon RDS Postgres database on node.js using sequelize ORM

I'm currently working on migrating an environment set up in Heroku over to the Amazon Web Services stack (RDS PostgreSQL, Elastic Beanstalk).
I'm facing some issues when trying to connect to PostgreSQL through the sequelize.js ORM. Error message below:
Unhandled rejection SequelizeHostNotFoundError: getaddrinfo ENOTFOUND
[host].
I can connect to the database through pgAdmin so I know the service is working, and the following configuration has worked on Heroku:
sequelize = new Sequelize(process.env.DATABASE_URI, {
dialect: 'postgres',
protocol: 'postgres',
logging: true,
timestamps: false
})
DATABASE_URI is formatted in the following way:
postgres://[db_username]:[db_password]#[hostname]:[port]/[db_name]
Any help would be greatly appreciated. Thanks in advance!
I was able to solve my issues here. Essentially, I solved it by setting up the following correctly within the environment.:
Formatting URI correctly - (Following the syntax above, I was able to get it to work)
Enabling security provisions for Amazon RDS & Elastic Beanstalk - I had to enable Inbound access to the Amazon RDS instance for the Security group / Instance Role that the Elastic Beanstalk was running under. (I got caught up in the fact that I was able to hit RDS through my local computer. By default, it seems RDS sets up the IP that you are using to be able to use it... which makes sense..)
I had a very similar problem, and it turned out I had a question mark in my password — causing half the password and the remainder of the connection URL to be ignored (as apparently part of the URL search portion).
Something like:
new Sequelize("postgres://fred:xj78?23#example.com/db");
Where we end up with username: fred, password: xj78, and everything else blank.
Escaping the question mark as %3F fixes the issue.

MQTT Js Last Will Message not getting published

I have the below code -->
var last_will = new Paho.MQTT.Message("last message");
last_will.destinationName = "Bridge123";
client = new Paho.MQTT.Client("broker.mqttdashboard.com", Number("8000"), "AX123");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect} , {willMessage:last_will});
When i disconnect the client i expect a last will message being sent to the topic i have created .. Am using Paho 's mqtt version -3.1 .. Websockets are getting created fine but i do not see the last will message ...
Can anyone guide here ?
Adding the bigger picture :
I have a Python script p gathering current on / off status of a IOT device in the local environment and publishing to a topic "IOT1" over mqtt . I do not want the python script always running to get status from the IOT device as it overloads the device .. To solve this i am in need of finding active clients for "IOT1" topic so that i run or pause the thread sending requests to the IOT device in the local environment .. Is there a way other than the last will message to know this ?
Last Will and Testament messages are only published if client does not disconnect cleanly.
If you close the connection gracefully it will not be sent.
Only when the server fails to receive a message or ping packet in the time out period will the server send the message.
willMessage should be the property of the first object. See below code snippet.
client.connect({onSuccess:onConnect, willMessage:last_will});

Categories