简体   繁体   English

如何配置SQL Server以允许本地或远程计算机上的数据库连接?

[英]How do you configure SQL Server to allow a database connection locally or from a remote machine?

How do you configure SQL Server to allow a database connection locally or from a remote machine? 如何配置SQL Server以允许本地或远程计算机上的数据库连接? I have a simple test with user=sa and password=123456. 我有一个用user = sa和密码= 123456的简单测试。 I can login to the server instance using SQL Management Studio with SQL Server and Windows Authentication mode enabled. 我可以使用启用了SQL Server和Windows身份验证模式的SQL Management Studio登录服务器实例。 I tried to login from another computer (Linux) using mssql module from npm to connect and I get a message: 'Login failed for user \\'sa\\'.', code: 'ELOGIN' . 我试图从另一台计算机(Linux)使用npm的mssql模块登录进行连接,我收到一条message: 'Login failed for user \\'sa\\'.', code: 'ELOGIN'

That was after opening up port 1433 in windows firewall (Windows 10). 那是在Windows防火墙(Windows 10)中打开端口1433之后。 Here is my config and i get the same results from remote machine if i use computer name for server or IP address for server. 这是我的配置,如果我使用服务器的计算机名称或服务器的IP地址,我从远程机器获得相同的结果。 Note I'm using the demo database that can be downloaded for SQL Server 2016. 注意我正在使用可以为SQL Server 2016下载的演示数据库。

const config = {
    user: 'sa',
    password: '123456',
    // server: '192.168.12.14',
    server: 'DESKTOP-AAFERR',
    // port: '1433',
    database: 'AdventureWorks2016CTP3',
    pool: {
        max: 10,
        min: 0,
        idleTimeoutMillis: 30000
    }
}

What i tried to do was open SQL Server Configuration Manager and enable TCP/IP for the server instance. 我试图做的是打开SQL Server配置管理器并为服务器实例启用TCP / IP。 However when I did that, I was not able to login locally from SQL Server Management Studio anymore using SQL Server authentication. 但是,当我这样做时,我无法使用SQL Server身份验证从SQL Server Management Studio本地登录。 I would get message Login failed (Microsoft SQL Server, Error: 18456) . 我会收到消息Login failed (Microsoft SQL Server, Error: 18456) But I also still could not login remotely. 但我仍然无法远程登录。 So i disabled TCP/IP again so i could login locally. 所以我再次禁用TCP / IP,以便我可以在本地登录。

How do you configure SQL Server to allow a database connection locally or from a remote machine? 如何配置SQL Server以允许本地或远程计算机上的数据库连接? I opened port 1433 in the firewall. 我在防火墙中打开了端口1433。 What else do I need to configure in SQL Server Management Studio or SQL Server Configuration Manager? 我还需要在SQL Server Management Studio或SQL Server配置管理器中配置什么?

After going through all settings in SQL Server Configuration Manager, I noticed that the machine I'm working on has another database instance that is not the default instance but was using the default port 1433. I found this in the logs for the default instance Server TCP provider failed to listen on 1433, TCP port is already in use. 在完成SQL Server配置管理器中的所有设置后,我注意到我正在处理的机器有另一个数据库实例,它不是默认实例,而是使用默认端口1433.我在日志中找到了默认实例Server TCP provider failed to listen on 1433, TCP port is already in use. And confirmed this by looking at the settings for the other database instance. 并通过查看其他数据库实例的设置来确认这一点。 So i changed the default instance I was working with to run on a different port and everything worked. 所以我改变了我正在使用的默认实例,以便在不同的端口上运行,一切正常。

Steps To Configure SQL Server to Allow a Database Connection Locally Or From a Remote Machine? 配置SQL Server以允许本地或远程计算机上的数据库连接的步骤?

Follow the steps microsoft outlines in this link . 按照此链接中的 microsoft轮廓步骤操作。 Summary: 摘要:

  1. Enable TCP/IP 启用TCP / IP
  2. Configure Fixed Port (this is where my error was, I had configured a port that was already in use) 配置固定端口(这是我的错误,我已经配置了一个已经在使用的端口)

Note: You will need to restart SQL Services for the changes to take effect. 注意:您需要重新启动SQL服务才能使更改生效。 Visit this link to see how to accomplish that with SQL Server Configuration Manager, SQL Server Management Studio, net Commands from a Command Prompt window, Transact-SQL, or PowerShell. 访问此链接 ,了解如何使用SQL Server配置管理器,SQL Server Management Studio,命令提示符窗口中的网络命令,Transact-SQL或PowerShell完成此操作。

  1. Open Ports in Firewall 在防火墙中打开端口
  2. Connecting to the Database Engine from Another Computer 从另一台计算机连接到数据库引擎
  3. Connecting Using the SQL Server Browser Service 使用SQL Server Browser服务进行连接

Note that I replaced steps 4 and 5 with the following steps on a Linux machine running a NodeJS application: 请注意,我在运行NodeJS应用程序的Linux机器上使用以下步骤替换了步骤4和5:

  1. npm install mssql npm install mssql
  2. Follow the custom configurations based on your preferences. 根据您的偏好遵循自定义配置。 You can look at my example from the original post. 您可以从原始帖子中查看我的示例。 Note you will need to uncomment the port and replace 1433 with the custom port you specified when you configured the fixed port. 请注意,您需要取消注释port并将1433替换为您在配置固定端口时指定的自定义端口。

If you run into problems, check the server log for the SQL Server database instance you are working with. 如果遇到问题, 请检查服务器日志中是否有您正在使用的SQL Server数据库实例。 That's where the clues were for my problem. 这就是我的问题的线索所在。

  1. In the Microsoft SQL Server Management Studio, expand the SQL Server. 在Microsoft SQL Server Management Studio中,展开SQL Server。
  2. In the Object Explorer, expand Management → SQL Server Logs. 在对象资源管理器中,展开管理→SQL Server日志。

Probably this is the best method 可能这是最好的方法

var config = {
    user: '',
    password: '',
    server: '', 
    database: '' 
};
var sql = require('mssql')
var conn = new sql.Connection(configBD.config)


sql.connect(configBD.config, function (err) {


if (!err) {


 console.log('Database  is connected ... \n\n')
  } else {
    console.log('Error connecting database ... \n\n')
  }
})

    var request = new sql.Request()
request.query(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio 2013中配置SQL Server以允许远程连接 - How to configure SQL Server in Visual Studio 2013 to allow remote connection 从远程计算机查看sql server数据库 - viewing sql server database from a remote machine 允许SQL Server远程连接 - Allow SQL Server Remote Connection 如何配置BizTalk WCF-SQL适配器以从SQL Server 2012“永远在线”副本数据库获取数据? - How do you configure a BizTalk WCF-SQL adapter to get data from a SQL Server 2012 “always on” replica database? 从远程服务器创建本地数据库(SQL Server)以进行本地测试环境 - Creating locally database (SQL Server) from remote server for locally test environment 使用 Azure,通过 AWS 远程连接到 SQL 服务器数据库在本地工作,但在部署时不能 - With Azure, Remote connection to SQL server database through AWS works locally, but not when deployed 你如何在本地加载dev数据库(服务器)? - How do you stress load dev database (server) locally? 如何配置SQL Server以允许通过IIS进行访问 - How do I configure SQL Server to allow access via IIS 当SQL Server BIDS安装在远程计算机而非本地上时,如何通过Excel宏执行SSIS包? - How to execute an SSIS package through Excel Macro when SQL Server BIDS is installed on a remote machine and NOT locally? 连接到远程机器中的数据库 - python - SQL Server - Connect to database in Remote machine - python - SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM