JDBC connection string with instance name and doma

2020-02-14 02:38发布

问题:

I have a database created in SQL Server with the following configuration:

Also, I am trying to connect to the database named EDS.

For that I created the following details:

Should i have domain in the string or should it be in the username? When i go to the database properties i see the owner has. Also, is the url correct on the instance part according to the image? it looks like it is not able to go to that particular instance.

Also, this is the configuration for the connection (using Windows Authenticaton)

When I put in the username I am getting the following error log:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user '. ClientConnectionId:e812971f-b03c-4210-9dbd-de0791bcc304

回答1:

When specifying the location of the SQL Server instance, one normally provides serverName\instanceName or serverName:portNumber, not both. That is, either

jdbc:sqlserver://INNOWAVE-99\SQLEXPRESS01;databaseName=EDS

or

jdbc:sqlserver://localhost:1433;databaseName=EDS

(assuming that the SQLEXPRESS01 instance has been explicitly configured to listen on port 1433, which is not usually the case for a SQL Express instance).

As mentioned in the documentation for Building the Connection URL

If both a portNumber and instanceName are used, the portNumber will take precedence and the instanceName will be ignored.

There is no domain= property defined for the connection URL for Microsoft's JDBC driver for SQL Server. Logging in to the SQL Server instance with Windows domain credentials is done implicitly using the integratedSecurity=true connection property (and not explicitly providing a username and password); details here.