Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to SQL Azure Database with sequelize, but SQL Server on localhost works fine

Tags:

People also ask

Can not connect to Azure SQL server?

If the application persistently fails to connect to Azure SQL Database, it usually indicates an issue with one of the following: Firewall configuration. The Azure SQL database or client-side firewall is blocking connections to Azure SQL Database.

How do I connect to premise SQL Server to Azure SQL Database?

Connect with SSMSOn the on-premises client computer, open SQL Server Management Studio. In the Connect to Server dialog box, enter the fully qualified host name for your managed instance in the Server name box. Select SQL Server Authentication, provide your username and password, and then select Connect.

Is Azure SQL compatible with SQL Server?

Azure fully supports running any edition of SQL Server on IaaS (VM). Combined with 'Always On' availability groups you will be able to achieve full compatibility with legacy on-premises SQL installs.


I have deployed a few sites to Heroku with MongoDB, but this is the first time I've made a site with SQL and tried to deploy to Azure, so I'm probably missing something obvious.

I have been developing a website on my dev machine using Node.js, a SQL Server Database, and Sequelize as the ORM. Everything works fine, but when I tried to deploy to Azure with a connection string I can't connect with the SQL Azure database. I can use SQL Server Management Studio to connect with the empty database on Azure, so I'm sure my connection info is correct.

When I tried to deploy to Azure, I tried with the connection string that Azure provides:

var Sql = require('sequelize');
var sql = new Sql('Driver={SQL Server Native Client 11.0};Server=tcp:server.database.windows.net,1433;Database=databasename;Uid=UserName@server;Pwd={password};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;');

When I try to connect with this string, the error I get is:

C:\Users\username\Documents\GitHub\event-site\node_modules\sequelize\lib\sequelize.js:110
    options.dialect = urlParts.protocol.replace(/:$/, '');
                                       ^

TypeError: Cannot read property 'replace' of null
    at new Sequelize (C:\Users\v-mibowe\Documents\GitHub\event-site\node_modules\sequelize\lib\sequelize.js:110:40)
    at Object.<anonymous> (C:\Users\v-mibowe\Documents\GitHub\event-site\routes\db-routes.js:68:11)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (C:\Users\v-mibowe\Documents\GitHub\event-site\server.js:16:1)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

db-routes.js:68:11 is the connection string to the db.

When I try to configure my connection with the following, the server no longer crashes or gives an error, but none of the content that should be created by the code in the schema is created. That code looks like this:

var Sql = require('sequelize');
var sql = new Sql('dbname', 'UserName@server', 'password', {
  host: 'server.database.windows.net',
  dialect: 'mssql',
  driver: 'tedious',
  options: {
    encrypt: true,
    database: 'dbname'
  },
  port: 1433,
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  }
});

My original connection to my localhost (which works fine) looks like this:

var Sql = require('sequelize');
var sql = new Sql('dbname', 'username', 'password', {
  host: 'localhost',
  dialect: 'mssql',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
  }
})

Thanks in advance for all the help!