我是 (Java) FitNesse 和 SQL Server 的新手,我想使用 DbFit 进行基本的 SQL 测试,
我在 root 中有以下内容:
!path c:\fitnesse\lib\dbfit.jar
!path c:\fitnesse\lib\fitlibrary.jar
!path c:\fitnesse\lib\sqljdbc4.jar
|Import|
|dbfit.SqlServerTest|
我的 HelloWorldTest 中有以下内容,
!contents -R2 -g -p -f -h
!|dbfit.SqlServerTest|
|Connect|LOCALSQLEXPRESS|sa|Password|somePassword:|
|eg.Division|
|numerator|denominator|quotient?|
|10 |2 |5 |
|12.6 |3 |4.2 |
|100 |4 |33 |
我尝试过的:
- 我仔细检查了我的 SQLExpress 用户名和密码,并且 SqlServer 实例位于本地主机。我怀疑这是防火墙问题。 (不可否认,我对防火墙的理解很薄弱。)
- 查看 SQL Server 配置管理器 (SSCM),
- 我看到“SQL Server (SQLEXPRESS) 作为 ID 为 2316 的进程运行,
- 使用 PowerShell 命令“nestat -a -no | Select-String 2316”,我在端口 55618 上看到该进程。
- 在 SSCM 中,我随后在“SQL Native Client 11.0 配置(32 位)”和“SQL Native Client 11.0 配置”中创建了名为“LOCALSQLEXPRESS”的别名,因为我不知道我的 JDBC 使用了什么。 (显然,用于 SQL Server 的 JDBC 不支持命名实例,当我尝试直接连接到\localhost\SQLEXPRESS 时,我得到一个异常告诉我) 我还在“SQLEXPRESS 协议(protocol)”中启用了“TCP/IP”和“共享内存”。
运行测试时出现以下错误:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host LOCALSQLEXPRESS, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
(注意端口号 1433,尽管我的别名指向端口 55618。)
这是我在 StackOverflow 上的第一篇文章,请原谅我的愚蠢行为。任何人都可以阐明吗?
最佳答案
我希望 lingo_journey 已经解决了这个问题。对于可能有同样问题的其他人,我最初也无法使命名实例与多参数连接一起工作。
为了解决这个问题,我改用连接字符串作为 Connect 的参数:
1) 确保 SQL Server Browser 服务正在运行(如上面评论中所述)
2) 如下更改连接参数:
!| Connect | jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=DB_NAME;integratedSecurity=true |
以下使用 SQL Server 身份验证也能正常工作(这可能更适用于 lingo_journey:
!| Connect | jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=DB_NAME;user=user1;password=Welcome!|
请注意,在我在网上看到的一些示例中,sqlserver: 已从连接字符串中省略,这对我不起作用。
关于java - 尝试使用 Fitnesse 和 DbFit 以及 SQL Server 时出现 SQLServerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13258469/