从禁用TCP的Java连接到SQL Server [英] Connecting to SQL Server from java with TCP disabled
问题描述
我正在尝试从Java连接到本地数据库(SQL Server 2008). 我已根据客户要求禁用了tcp连接,但无法连接. 我也必须禁用SQL Server浏览器服务.
I'm trying to connect to a local database (SQL Server 2008) from Java. I have disabled the tcp connections per customer requirements and I can't connect. I have to disable too the service SQL Server Browser.
我用Java编写下一条语句:
I write the next statement in Java:
conexion = DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;user=user;password=password");
,我遇到以下错误:
"java.net.SocketTimeoutException: 接收超时".(然后它告诉我 可能有防火墙, 我应该运行SQL Server 浏览器).
"java.net.SocketTimeoutException: Receive timed out". (then it tells me that probably there is a firewall and that I should run the SQL Server Browser).
如果我尝试从Microsoft SQL Server Managment Studio连接,并且可以使用相同的参数进行连接:
If I try to connect from the Microsoft SQL Server Managment Studio and I can connect whith the same parameters:
Server type: Database Engine
Server name: localhost\SQLEXPRESS
Authentication: SQL Server Authentication
User: user
Password: password
我不知道我在Java中是否做错了什么,但是SQL Server Managment Studio实际上是一个客户端,因此,如果它可以连接任何客户端,则应该可以.
I don't know if I'm doing something wrong i Java but SQL Server Managment Studio is actually a client, so if it can connect any client should can.
请回答.如果您需要更多信息,请提出要求.
Please answer. If you need more information just ask for it.
推荐答案
不幸的是,Microsoft的JDBC驱动程序不支持与SQLServer的命名管道连接.您可以尝试查找和使用其他JDBC驱动程序.
Unfortunately, Microsoft's JDBC driver does not support named pipes connections to SQLServer. You can try finding and alternative JDBC driver to use.
看看 jTDS .它是免费的开放源代码,并且使用命名管道连接到SQLServer.
Take a look at jTDS. It's free, open source, and it connects to SQLServer using named pipes.
这篇关于从禁用TCP的Java连接到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!