azure database and google spreadsheet connection error "Failed to establish a database connection. Check connection string, username and password." - azure

I tried many ways to fix this error :
"Failed to establish a database connection. Check connection string, username and password."
Code :
function AcessaVendas () {
var URL = 'jdbc:sqlserver://servername:49159'
var USER = 'visitant'
var PASS = '*******'
var conn = Jdbc.getConnection(URL, USER, PASS);
var stmt = conn.createStatement();
stmt.setMaxRows(10000);
var start = new Date();
var rs = stmt.executeQuery( myquery());
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Dados");
ss.getRange('a2:h1000').clearContent();
var cell = ss.getRange('a2');
var row = 0;
while (rs.next()) {
for (var col = 0; col < 11; col++) {
cell.offset(row, col).setValue(rs.getString(col + 1));
}
row++;
}
rs.close();
stmt.close();
conn.close();
var end = new Date();
Logger.log('Time elapsed: ' + (end.getTime() - start.getTime()));
}
First i have tried changing the azure servername for the server ip, then i tried adding the database name like,
db = "databasename"
URL = 'jdbc:mysql://servername:49159'+'/'+ db;
I also thought that maybe the database user that i have created in the sql server management studio could be the problem, because he has db_datareader role but i tried using the user with db_owner role and it also didn't work.
I also tried to put every Google App Server IPs whitelist range in the firewall of the azure server(one at once, or do i have to put ervery ip range at once?).
Could someone give me a help?

Related

Accessing sqlite databases on remote machine with static adress (Electron / Nodejs / fs)

I am trying to access an sqlite file on a local area network machine located in "sqlite" folder, on windows file explorer I access it using the IP address "192.168.5.15/sqlite/db.sqlite", however when the electron aplication tries to access it, the path is converted to the local machine path "c:/application ....../192.168 ....".
please how can I just point the file directly using the static IP adress without converting it to local machine path?
here is the code:
// login_app.js
var route = require('../../libs/router.js'); //my lib
var dbPath = "192.168.5.15/sqlite/db.sqlite" // here is the path i want to keep it static
function login() {
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
if(email == "" || password == ""){
alert("Please Enter Your email & Password ...");
return;
} else{
var sql = require('sql.js'); //Import sqLite
var fs = require("fs"); //Import Files driver
var SHA256 = require("crypto-js/sha256"); //Crypting Library
try {
var filebuffer = fs.readFileSync(dbPath); //here is the problem it converts the file to local machine path c:/..../192....
if (filebuffer != null) {
var db = new SQL.Database(filebuffer);
} else {
var db = new SQL.Database();
console.log("No Database");
}
// Prepare an sql statement
var stmt = db.prepare("SELECT * FROM users WHERE email=:emailid");
// Bind values to the parameters and fetch the results of the query
var result = stmt.getAsObject({':emailid' : email});
if(result.password == null) alert('Account not existing, please contact Your Administrator ...');
else{
if(SHA256(password) == result.password) {
route.data.relocate('dashboard');
}
else alert('Wrong Login credentials, please try again ...');
}
} catch (e) {
console.log(e);
}
}
}
as suggested by GregHNZ var dbPath = "//192.168.5.15/sqlite/db.sqlite" worked, so just used double slash.
Thanks GregHNZ

Office 365 'Create Event' Rest API is giving error

I am new user on stackoverflow as well as in office 365 development using node.js.
I am successfully getting User(my own office 365 account) mails,calendar events using this tutorial (https://dev.outlook.com/RestGettingStarted/Tutorial/node)
but when i am trying to Create an Event in my calender it gives me below error
"{"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}"
Please provide me suggestions on the same.
Below is the code for creating event which i copied from [https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations#CreateEvents] here
function createEvent(response, request) {
var cookieName = 'node-tutorial-token';
var cookie = request.headers.cookie;
// if (cookie && cookie.indexOf(cookieName) !== -1) {
console.log("Cookie: ", cookie);
// Found our token, extract it from the cookie value
var start = cookie.indexOf(cookieName) + cookieName.length + 1;
var end = cookie.indexOf(';', start);
end = end === -1 ? cookie.length : end;
var token = cookie.substring(start, end);
console.log("Token found in cookie: " + token);
var event = new outlook.Microsoft.OutlookServices.Event();
event.subject = 'Your Subject';
event.start = new Date("October 30, 2014 11:13:00").toISOString();
event.end = new Date("October 30, 2014 12:13:00").toISOString();
// Body
event.body = new outlook.Microsoft.OutlookServices.ItemBody();
event.body.content = 'Body Content';
event.body.contentType = outlook.Microsoft.OutlookServices.BodyType.Text;
// Location
event.location = new outlook.Microsoft.OutlookServices.Location();
event.location.displayName = 'Location';
// Attendee
var attendee1 = new outlook.Microsoft.OutlookServices.Attendee();
var emailAddress1 = new outlook.Microsoft.OutlookServices.EmailAddress();
emailAddress1.name = "abc";
emailAddress1.address = "abc#abcdt.onmicrosoft.com";
attendee1.emailAddress = emailAddress1;
event.attendees.push(attendee1);
var outlookClient = new outlook.Microsoft.OutlookServices.Client('https://outlook.office365.com/api/v1.0',
authHelper.getAccessTokenFn(token));
outlookClient.me.calendar.events.addEvent(event)
.then(function (response) {
console.log(response._Id);
}, function (error) {
console.log(error);
});
}
Make sure your app has requested for calendar.readwrite permission and you need this to create new events. In the example you followed, your app registered for only Calendar.Read permissions (see below).
You should instead go to https://dev.outlook.com/AppRegistration to register an app with Calendar.ReadWrite permission which is required to create new events.

Determine whether the domino server is running or not ( session.getDatabase(..) takes too long when the corresponding server is down )

I have approximately 4-5 users on different servers and need to find free time based on the calendar entries. Till last night the functionality was working great, however, today we just figured out a small issue/bug. One of the server machine was offline today and SSJS took around a minute (60 seconds) to figure that out.
Is there any such option to verify whether the server is running? I am asking this since session.getDatabase takes a long time to provide any results in such case.
Just for reference, below is my code to verify users mail database accessibility. It works perfectly fine when all servers are up, however, the waiting time is too long when any server is down.
// Set up the names
var names = new java.util.Vector();
var inaccessible_calendars = new java.util.Vector();
var infoDoc:NotesDocument= database.getDocumentByUNID(context.getUrlParameter('refId'));
var members:java.util.Vector = infoDoc.getItemValue("members");
names = infoDoc.getItemValue("members");
//var members:java.util.Vector = infoDoc.getItemValue("members");
var membersIterator = members.iterator();
var maildb ="";
while(membersIterator.hasNext()){
var val = membersIterator.next();
var nab:NotesDatabase=session.getDatabase(database.getServer(),"names.nsf")
var nview:NotesView=nab.getView("($NamesFieldLookup)")
var doc:NotesDocument=nview.getDocumentByKey(val,true)
if(doc){
var email = doc.getItemValueString("MailFile")
var emailServer = doc.getItemValueString("MailServer")
doc.recycle()
nview.recycle()
nab.recycle()
maildb=#LowerCase(emailServer)+'!!'+#LowerCase(email)+ '.nsf'
var emailServerCN = #Name("[CN]",#LowerCase(emailServer));
var emailDBName = #LowerCase(email)+ '.nsf';
emailDBName = emailDBName.replace("\\","\/");
try{
if(session.getDatabase(emailServerCN.toString(),emailDBName.toString())==null){
names.remove(val);
inaccessible_calendars.add(val);
}else{
var emailDB:NotesDatabase = session.getDatabase(emailServerCN.toString(),emailDBName.toString());
if(!(emailDB.getCurrentAccessLevel()>0)){
names.remove(val);
inaccessible_calendars.add(val);
}
}
}catch(err){
names.remove(val);
inaccessible_calendars.add(val);
}
} else {
nview.recycle()
nab.recycle()
maildb= ""
}
}
if(!inaccessible_calendars.isEmpty())
return "Following calendars are not accessible"+inaccessible_calendars.toString()+"*";
Any help would be really appreciated.
Are these database in a cluster? Can they be? If so then when you open it there an "OpenWithFailOver" method I forget the exact syntax. But if the database in unavailable it should open another in the cluster.

C# LDAP SetPassword throws The RPC server is unavailable

I am trying to create a new user -> set password and enable account .
earlier i was using 1 single object , but after looking at a few posts i decided to use 'using' for 3 different operations
string strDisplayName = txtFirstName.Text + " " + txtLastName.Text;
string strUser = txtLoginName.Text;
string pw = "pass#123";
using (var objADAM = new DirectoryEntry("LDAP://" + adlink + "/CN=Users,DC=SS,DC=COM", "ss\\luser", "pass#123", AuthenticationTypes.Secure))
{
const long ADS_OPTION_PASSWORD_PORTNUMBER = 6;
const long ADS_OPTION_PASSWORD_METHOD = 7;
const int ADS_PASSWORD_ENCODE_CLEAR = 1;
string strPort = "389";
int intPort = Int32.Parse(strPort);
using (var objUser = objADAM.Children.Add("CN=" + strUser, "user"))
{
objUser.Properties["sAMAccountName"].Add(strUser);
objUser.CommitChanges();
}
}
using (var user = new DirectoryEntry("LDAP://" + adlink + "/CN=" + strUser + ",CN=Users,DC=SS,DC=COM", "ss\\rluser", "pass#123"))
{
user.Invoke("SetPassword", new object[] { "password" });
user.CommitChanges();
}
using (var user = new DirectoryEntry("LDAP://" + adlink + "/CN=" + strUser + ",CN=Users,DC=SS,DC=COM", "ss\\rluser", "pass#123"))
{
//Enable account and change password on first logon flag
user.Properties["userAccountControl"].Value = 0x200;
user.Properties["pwdLastSet"].Value = 0;
user.CommitChanges();
}
I must mention, that i am outside the domian, and trying to connect to a remote AD on another domain . The credential's passed however are the ADMIN
The user creation goes on smoothly (after some hiccups with port opening & LDAP connections) , but the issue occurs when the invoke ->setpassword is called .
The error is :"the RPC server is unavailable " , just to make sure i am not doing something wrong in my code, i downloaded a LDAP admin tool and tried to reset the password of an existing user ->same error
steps
-checked the RPC service running
-opened RPC ports -135 ,blah blah..basically every port there is to open :|
any help is appreciated .
Thanks
Rajat
For example:
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://dnsname.domain.com:389/OU=Companies;
Microsoft recommends accessing using DNS.
if the machine you are accessing is connected to a different domain, you must specify it as "ip dnsname" in the hosts file in the "C:\Windows\System32\drivers\etc " directory.
using adlink is string domain, because AD method Invoke using domain name: "abc.com"

Reset ldap user password (Error : The server cannot handle directory requests. )

I am using this code:
LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier("DOMAIN",636));
connection.SessionOptions.VerifyServerCertificate =
new VerifyServerCertificateCallback((con, cer) => true);
connection.SessionOptions.ProtocolVersion = 3;
connection.AuthType = AuthType.Basic;
connection.Credential = new NetworkCredential("CN=user,CN=Users,DC=DOMAIN","password!");
connection.SessionOptions.SecureSocketLayer=true;
using(connection)
{
connection.Bind();
SearchRequest request = new SearchRequest("CN=Users,DC=DOMAIN", "CN=mayank", System.DirectoryServices.Protocols.SearchScope.Subtree);
SearchResponse response = (SearchResponse)connection.SendRequest(request);
SearchResultEntry entry = response.Entries[0];
DirectoryAttributeModification modifyUserPassword = new DirectoryAttributeModification();
modifyUserPassword.Operation = DirectoryAttributeOperation.Replace;
modifyUserPassword.Name = "unicodePwd";
modifyUserPassword.Add(GetPasswordData("admin1234!"));
ModifyRequest modifyRequest = new ModifyRequest(entry.DistinguishedName, modifyUserPassword);
DirectoryResponse dirResponse = connection.SendRequest(modifyRequest);
}
This successfully connects to LDAP but when one attempts to change the password, it throws an error stating "The server cannot handle directory requests."

Resources