使用JDBC连接SQL Server 2000 命名实例(Named Instance)
最近比较闲,就爱摆弄一些玩意,前时间对ruby on rails比较感兴趣,就想继续看看,但是系统坏了好几次,前段时间配好的eclipse+rdt+sqlserver的环境也就得重新diy了;
按照 Setting up a Rails Development Environment on Windows Using Eclipse上的步骤,一步一步走的挺顺利的,可是到Install the DBEdit Eclipse plugin的时候,想恢复以前的直接连接自己比较熟悉的SQL Server 2000,可是死活也无法连上,老是报[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.错误,起初以为是没有打sp3包,就干脆重新安装了个msde sp4的命名实例,可是懵了,怎么连命名实例啊,想起总是用net start mssql$InstanceName 启动命名实例服务,突发其想以为可用jdbc:microsoft:sqlserver://serverName$InstanceName:Port来连接还是报[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.错误,说明猜想不对,google了一下找了n多资料一直没有解决,最后在msdn上发现有这么篇文章How To Connect to a SQL Server 2000 Named Instance with JDBC 找到解决方案了:
To find the SQL Server instance port number, follow these steps:
1. | On the Microsoft SQL Server 2000 server, start the SQL Server Network Utility. |
2. | Click the General tab, and then click the instance you want from the Instances drop-down menu. |
3. | Click TCP/IP, and then click Properties. Note that the port number for this instance appears in the Properties dialog box. |
As soon as you have this value, you can use it in your connection URL when you connect to SQL Server through JDBC. The following is an example of a typical connection URL:
jdbc:microsoft:sqlserver://yourServerName:1433;user=yourUser;password=yourPwd
也就是说不是用jdbc:microsoft:sqlserver://serverName$InstanceName:Port这个主观臆造的URL来连接,而是使用上面的串,其中yourServerName是服务器名,1433应该替换成你命名实例的端口号,在这个url中根本体现不出命名实例名,比如我的连接url:jdbc:microsoft:sqlserver://oy-m:2046(我新安装的命名实例为ruby,端口号为2046),就这么简单……