我正在使用 MS SQL DB 在 jboss 中创建数据源。所需的驱动程序已加载到模块下。
测试连接失败。机器之间的连接正常。
连接网址 - jdbc:microsoft:sqlserver://localhost\dev;databaseName=dev_db
“WFLYJCA0040:无法调用操作:WFLYJCA0047:连接无效”
有人可以帮忙吗?
答案1
官方文件指出:
The general form of the connection URL is
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
where:
jdbc:sqlserver:// (Required) - Is known as the subprotocol and is constant.
serverName (Optional) - Is the address of the server to connect to. This address can be a DNS or IP address, or it can be localhost or 127.0.0.1 for the local computer. If not specified in the connection URL, the server name must be specified in the properties collection.
instanceName (Optional) - Is the instance to connect to on serverName. If not specified, a connection to the default instance is made.
portNumber (Optional) - Is the port to connect to on serverName. The default is 1433. If you're using the default port, you don't have to specify the port, nor the preceding : in the URL.
Note
For optimal connection performance, you should set the portNumber when you connect to a named instance. This will avoid a round trip to the server to determine the port number. If both a portNumber and instanceName are used, the portNumber will take precedence and the instanceName will be ignored.
property (Optional) - Is one or more option connection properties. For more information, see Setting the connection properties. Any property from the list can be specified. Properties can only be delimited by using the semicolon (;), and they can't be duplicated.
你正在定义本地主机作为服务器名称,仍然存在疑问,您声明“机器之间的连接看起来良好”,这意味着您在连接字符串中输入了错误的服务器名称,或者您弄乱了描述设置的内容。
最后,建议使用以下格式:服务器名称和端口号(请使用您配置的端口号):
jdbc:sqlserver://dbservername:1433;encrypt=true;databaseName=dev_db;integratedSecurity=true;
您提到了连接字符串,但有些应用程序需要设置“连接属性”,而不是连接字符串。请检查一下。
最后请检查 JBoss服务器日志对于任何特定于驱动程序的问题。
答案2
配置下面的连接字符串并解决了该问题
jdbc:sqlserver://服务器名称;数据库名称=dev_db;实例名称=sqldev;selectMethod=cursor;trustServerCertificate=true