简体   繁体   中英

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:

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.

I can see from the Security->Login folder there is a "sa" entry

However when I run the web application I am getting this error:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Network error IOException: Connection refused: connect)

I seems that the user: "sa" is not authenticated to access the database?

If so, how can I use the SQL Server management studio to fix this?

Make sure authentication mode is set to Mixed. It's set to Windows authentication mode as default which disables sa account. See here: http://msdn.microsoft.com/en-us/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). To do so launch SQL Management Studio and in connection preferences set: Authentication - SQL Server authentication , login - sa , password - your password . Then click Options , connection properties and select tcp/ip as protocol. Check if you can login.

To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either.

e.g, c:>telnet servername 1433

to enable telnet client on windows

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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