typeorm: Failed to connect to localhost:1433 - Could not connect (sequence)

Issue type: [X ] question

Database system/driver: [X] mssql

TypeORM version: [X] latest

Hi everyone,

I’m new to typeorm. For now, I’m trying to connect to my local sql server which is:

Server name: .\SQLEXPRESS Port: 1433 (default)

This is my configuration file (ormconfig.json):

{
   "type": "mssql",
   "host": "localhost",
   "port": 1433,
   "username": "sa",
   "password": "mypassword",
   "database": "HelloWorld",
   "synchronize": true,
   "logging": false,
   "entities": [
      "src/entity/**/*.ts"
   ],
   "migrations": [
      "src/migration/**/*.ts"
   ],
   "subscribers": [
      "src/subscriber/**/*.ts"
   ],
   "cli": {
      "entitiesDir": "src/entity",
      "migrationsDir": "src/migration",
      "subscribersDir": "src/subscriber"
   }
}

When I typed npm run start in my command prompt window, it threw me an error: Failed to connect to localhost:1433 - Could not connect (sequence)

If I connect to my database using SMSS tool, it worked normally.

I’ve tried following this solution to turn on TCP connection of my database, but it still didn’t work.

What am I doing wrong ?

Thank you.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18

Most upvoted comments

Hi @IbraBach,

Try below steps:

  1. First check whether you are able to connect to Sql Server Management Studio or not.
  2. If first point works then check Sql Server(InstanceName) and Sql Server Browser services should be running.
  3. If second point is also ok then check in Sql Server Network Configuration. a) TCP/IP port should be enabled (default is disabled) and right click and enabled it. b) Go to TCP/IP properties, IP Address and checlk IP1 settings (IP Address: 127.0.0.1, TCP dynamic port: Blank, Port: 1443), Rest all IPs (TCP dynamic port: Blank, Port: 1443)

Try this I hope this should work.

mssms

sqlservices

tcpip

tcpips

Finally I resolved my issue.

I forgot turning on SQL Server Browser service on my machine.

I followed those steps to turning on SQL Server Browser.

I used JetBrain DataGrip tool to try to connect to my database, it detected my port was 65269 instead of 1433.

I think this issue can be closed.

I found this query on stack overflow

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on',N'', NULL, NULL, N'asc'
GO

Maybe will help if you’re using Microsoft SQL Server Management Studio and you don’t know how to get the port.

const config = { user: ‘your-user’, password: ‘your-password’, server: ‘localhost’, database: ‘your-database’, options: { encrypt: false // please add this for ms sql } };