简体   繁体   English

JDBC断管Mac

[英]JDBC Broken Pipe Mac

It's very strange but I am repeatedly getting this issue everytime I attempt to connect to SQL Azure via JDBC. 这很奇怪,但是每次尝试通过JDBC连接到SQL Azure时,我都会反复遇到此问题。

Environment: Eclipse Oxygen, Mac Sierra 10.12.6, JDK 1.8.0_141 环境:Eclipse Oxygen,Mac Sierra 10.12.6,JDK 1.8.0_141

I see the following error: 我看到以下错误:

Cannot create PoolableConnectionFactory (Broken pipe (Write failed) ClientConnectionId:ac4ed2ba-4563-4f3b-9bcc-441bff9e45e1)

I am trying to create the connection in the most basic of ways, via context.xml as such: 我正在尝试以最基本的方式通过context.xml创建连接:

 <Resource name="jdbc/sqlazure"
auth="Container"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
type="javax.sql.DataSource"
maxIdle="30"
username="<user>
password="<password>
url="jdbc:sqlserver://<dbname>.database.windows.net:1433;database=<db>;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
removeAbandonedTimeout="30"
logAbandoned="true" /> 

In my servlet init() I am getting the datasource as such: 在我的servlet init()中,我得到这样的数据源:

 ds = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/sqlazure");

And it is returning non-null. 并且它返回非null。 However when I try to get a connection: 但是,当我尝试建立连接时:

Connection con = ds.getConnection()

It hangs here and then times out with the broken pipe error. 它挂在这里,然后因管道错误而超时。 I have also whitelisted the appropriate IP addresses in the Azure portal. 我还在Azure门户中将适当的IP地址列入了白名单。

My SQLPro client is able to connect to the database and view its contents so shouldn't be any issue with username/password and connection string. 我的SQLPro客户端能够连接到数据库并查看其内容,因此用户名/密码和连接字符串应该不会有任何问题。

I have confirmed my hostname is set correctly. 我已经确认我的主机名设置正确。 using: 使用:

scutil --get HostName

I've tried everything I can think of but still no luck. 我已经尝试了所有我能想到的东西,但还是没有运气。 I am starting to think that there is some issue with the Java runtime on OSX. 我开始认为OSX上的Java运行时存在一些问题。 Anyone have any ideas ? 有人有想法么 ?

EDIT: I used the same exact files on Windows environment and JDK and did not see this issue. 编辑:我在Windows环境和JDK上使用了完全相同的文件,但没有看到此问题。 So I am to believe this is Mac specific... 所以我相信这是Mac专用的...

You may need to install Homebrew and Maven to make it work. 您可能需要安装Homebrew和Maven才能使其正常工作。 Please follow instructions provided here . 请按照此处提供的说明进行操作。

Hope this helps. 希望这可以帮助。

Regards, 问候,

Alberto Morillo 阿尔贝托·莫里洛(Alberto Morillo)

Your issue was very similar with the other SO thread How to connect to Azure SQL with JDBC . 您的问题与其他SO线程非常相似。 如何使用JDBC连接到Azure SQL Please try its solution which comes from the same issue post at here . 请尝试从此处的同一期文章获得解决方案。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM