jdbc.SQLServerException: Login failed for user for any user

后端 未结 4 837
你的背包
你的背包 2021-01-04 23:55

I trying to test the connection with my local sql DB. I have this code:

try{
    Class.forName(\"com.microsoft.sqlserver.jdbc.SQLServerDriver\").newInstance(         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-05 00:09

    Having been through this very recently the steps I took to solve pretty much the same problem were

    1. use SQL Server Management Studio to log in with the desired account and confirm access to read (and write if necessary)
    2. Use SQL Server Configuration Manager to confirm that the server instance is listening on the IP address being targetted
    3. Disable the firewall to check that isn't getting in the way (and add an exception if necessary for future use)

    The absolute kicker for me was understanding what IP addresses and ports the instance was set to listen on so that when I constructed the connection string the connection wasn't being rejected.

    Also, if you want to connect using Windows logins you need to ensure the SQL instance is configured for mixed mode authentication (i.e. to allow Windows and SQL logins)

提交回复
热议问题