Forum Discussion

Joe_C96's avatar
Joe_C96
Copper Contributor
Oct 25, 2024

Authentication issues when trying to Migrate Data using VS Code from SQL server

Hi,

 

I am trying to migrate data from our SQL database which is on one virtual machine to another virtual machine on the same network using VS code and Node JS. I keep getting authentication errors. On the SQL server the error is "Login failed for user 'xxxx'. Reason: Could not find a login matching the name provided. [CLIENT: xxx.xxx.xx.xx]". The user details entered are correct and I am admin on the SQL Server. I have checked all permissions.

 

Event ID: 18456

 

 

 

 

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    Joe_C96 

    ... and I am admin on the SQL Server.


    So you logon with your Windows credentials; how does your connection string look like?

  • Mks_1973's avatar
    Mks_1973
    Iron Contributor

    Please check these:

    Confirm SQL Server Authentication Mode
    Under "Security," ensure that SQL Server and Windows Authentication mode is selected if you're using SQL Server Authentication

    Verify User Exists on the Target Server
    Ensure the user 'xxxx' exists under Logins.
    If the user is missing, create it:
    Right-click on "Logins" > "New Login."
    Set the login name, choose "SQL Server Authentication," and set the appropriate password.

    Under "User Mapping," ensure the user is mapped to the relevant database with the correct role.

    check for your connection string is correctly formatted:
    sample format below:

    const sql = require("mssql");

    const config = {
        user: 'xxxx',
        password: 'your_password',
        server: 'your_server_ip_or_name',
        database: 'your_database',
        options: {
            encrypt: true, // for Azure
            trustServerCertificate: true // if using self-signed certificates
        }
    };

    sql.connect(config).then(pool => {
        // Use the connection
    }).catch(err => {
        console.error("SQL Connection Error:", err);
    });


    Verify that port 1433 (or the port your SQL Server is listening on) is open on both virtual machines, and if not please open.

    Also, confirm that SQL Server is configured to allow remote connections

    Ensure TCP/IP is enabled (SQL Server Configuration)

    Make sure you are using a compatible Node.js SQL Server driver, such as mssql or tedious

    Try connecting to the SQL Server from SSMS on the same machine where you are running VS Code. If it connects successfully, then the issue may lie with your Node.js code or configuration

    Please view the error log in SSMS under "Management" > "SQL Server Logs."

    If you've moved the database or had to restore it, SQL logins might lose their mappings. In such cases, you may need to map the login to the database manually:

    USE [your_database];
    GO
    ALTER USER [xxxx] WITH LOGIN = [xxxx];
    GO

    If SQL Server is configured with SSL, ensure your Node.js connection uses the encrypt option in the connection settings:
    options: {
        encrypt: true,
        trustServerCertificate: false // set to true if using self-signed certificate
    }

    Make sure there are no network policies or restrictions on your VMs blocking the connection.

    If your organization uses AD authentication, confirm that the credentials are valid and that the VM has network access to the AD server.

     

     

Resources