简体   繁体   English

如何将我的Web应用程序连接到SQL Server / SQL Server Express

[英]How to connect my web application to SQL Server / SQL Server Express

I am working with a web application that connects to a SQL Server database with this: 我正在使用与此连接到SQL Server数据库的Web应用程序:

jdbc.url=jdbc:jtds:sqlserver://127.0.0.1/MyDatabase
jdbc.username=sa
jdbc.password=password

I am relatively new to SQL Server, however I have successfully accessed a SQLEXPRESS instance through the SQL Server Management Studio. 我是SQL Server的新手,但是我已经通过SQL Server Management Studio成功访问了SQLEXPRESS实例。

I can see from the Security->Login folder there is a "sa" entry 我可以从“安全性”->“登录”文件夹中看到一个“ sa”条目

However when I run the web application I am getting this error: 但是,当我运行Web应用程序时,出现此错误:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; PropertyAccessException 1:org.springframework.beans.MethodInvocationException:属性'dataSource'抛出异常; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Network error IOException: Connection refused: connect) 嵌套的异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(网络错误IOException:连接被拒绝:connect)

I seems that the user: "sa" is not authenticated to access the database? 我似乎该用户:“ sa”是否未通过身份验证才能访问数据库?

If so, how can I use the SQL Server management studio to fix this? 如果是这样,如何使用SQL Server Management Studio修复此问题?

Make sure authentication mode is set to Mixed. 确保身份验证模式设置为“混合”。 It's set to Windows authentication mode as default which disables sa account. 默认情况下,它设置为Windows身份验证模式,从而禁用sa帐户。 See here: http://msdn.microsoft.com/en-us/library/ms143705%28v=sql.90%29.aspx 看到这里: http : //msdn.microsoft.com/zh-cn/library/ms143705%28v=sql.90%29.aspx

Edit: as Jacob suggested, make sure you can connect via TCP/IP (I assume it's used by the driver). 编辑:按照Jacob的建议,请确保您可以通过TCP / IP连接(我假设驱动程序已使用它)。 To do so launch SQL Management Studio and in connection preferences set: Authentication - SQL Server authentication , login - sa , password - your password . 为此,请启动SQL Management Studio并在连接首选项中设置: Authentication - SQL Server authenticationlogin - sapassword - your password Then click Options , connection properties and select tcp/ip as protocol. 然后单击Optionsconnection properties然后选择tcp/ip作为协议。 Check if you can login. 检查是否可以登录。

To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". 要检查是否启用了TCP / IP且端口未被阻塞,可以使用“ telnet 1433”。 Until telnet doesn't connect, jTDS won't either. 在telnet不连接之前,jTDS也不会连接。

e.g, c:>telnet servername 1433

to enable telnet client on windows 在Windows上启用telnet客户端

http://social.technet.microsoft.com/wiki/contents/articles/910.how-to-enable-telnet-client-in-windows-7.aspx http://social.technet.microsoft.com/wiki/contents/articles/910.how-to-enable-telnet-client-in-windows-7.aspx

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

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