Java SQL Server 2012无法打开数据库错误 [英] Java SQL Server 2012 Cannot open database error

查看:200
本文介绍了Java SQL Server 2012无法打开数据库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎遇到了错误:无法打开登录请求的数据库。将我的SQL Server数据库连接到用netbeans编写的Java应用程序时登录失败。

I seem to be running into the error: Cannot open database requested by the login. The login failed. when connecting my SQL Server database to a Java application written in netbeans.

我阅读了大量文章,并完成了以下工作:

I have read numerous articles and done the following:


  • 在UDP和TCP下允许1433端口到防火墙

  • Allowed the 1433 port to the firewall under UDP and TCP

将SQL Server配置管理器TCP / IP端口设置为1433

Set SQL Server Configuration Manager TCP/IP ports to 1433

将SQL Server Management Studio中的服务器身份验证更改为混合身份验证

Changed the server authentication in SQL Server Management Studio to mixed authentication

SQL Server Management Studio中允许的远程连接

Allowed remote connections in SQL Server Management Studio

我的连接字符串如下:

jdbc:sqlserver://localhost\\SQLEXPRESS:1433;DatabaseName = SASS; IntegratedSecurity=true; Trusted_Connection=true; 

我仍然收到以下错误:

Cannot open database "SASS" requested by the login. The login failed. ClientConnectionId:894b97b9-54d6-47cc-afd7-1473a460c09d

连续3天阅读后,我在我的智慧结束了。

After reading for 3 days straight, I am at my wits end.

推荐答案

我似乎已经弄清楚发生了什么。我已经改变了我的电脑设置并更新了很多东西,我一定是在打破了一些东西。

I seemed to have figured out what was going on. I had changed my pc's settings and updated so many things, I must've broken something along the way.

下面是一组说明,如果其他人遇到Java连接问题,我会解决这些说明。这是在新安装的计算机上完成的:

Below are a set of instructions that I've worked out in the event that anyone else has problems with Java connections. This was done on a newly installed machine:

将SQL Server数据库(2008或2012)连接到Java Netbeans应用程序:

Connecting a SQL Server Database (2008 or 2012) to a Java Netbeans Application:


  1. 安装SQL Server Management Studio 2008或2012

  2. 安装SQL Server
    a。将服务器实例命名为SQLExpress / SQLEXPRESS
    b。确保服务器接受混合的身份验证方法(SQL Server和Windows身份验证模式)
    c。向系统管理员提供密码:admin

  3. 安装最新的JRE和JDK

  4. 安装Netbeans

  5. 创建SQL Server Management Studio中的测试数据库以便稍后进行测试

  6. 更新防火墙以接受TCP和UDP的传入和传出端口1434

  7. 打开SQL Server配置管理器

  1. Install SQL Server Management Studio 2008 or 2012
  2. Install SQL Server a. Name the Server Instance SQLExpress/SQLEXPRESS b. Make sure that the server accepts mixed methods of authentication (SQL Server and Windows Authentication Mode) c. Give the System Administrator the password: admin
  3. Install the latest JRE and JDKs
  4. Install Netbeans
  5. Create a test database in SQL Server Management Studio to test later
  6. Update the firewall to accept the incoming and outgoing port 1434 for TCP AND UDP
  7. Open SQL Server Configuration Manager

a。停止SQL Server(SQLEXPRESS)和SQL Server Browser服务

a. Stop both the SQL Server (SQLEXPRESS) and SQL Server Browser services

b。在SQL Server网络配置下打开SQLEXPRESS的协议并启用TCP / IP

b. Open the Protocols for SQLEXPRESS under SQL Server Network Configuration and enable TCP/IP

c。启用所有端口(ESPECIALLY IPAll)并将端口设置为1434

c. Enable all ports (ESPECIALLY IPAll) and set the ports to 1434

d。再次启用服务(尤其是SQL Server浏览器)

d. Enable the services again (especially the SQL Server Browser)

将sqljdbc驱动程序添加到Java Netbeans应用程序

Add the sqljdbc driver to your Java Netbeans application

一个。将sqljdbc驱动程序添加到应用程序库(右键单击添加)

a. Add the sqljdbc driver to the application library (right click  add)

b。在服务选项卡下,展开数据库,然后右键单击驱动程序

b. Under the Services tab, expand "Databases" and right click on "Drivers"

c。将sqljdbc4驱动程序添加到服务中(右键单击新驱动程序...)

c. Add the sqljdbc4 driver to the service (Right click  New Driver…)

d。确保连接字符串类似于:
jdbc:sqlserver:// localhost\SQLEXPRESS; database = [数据库名称]; integratedSecurity = true;
其中localhost\SQLEXPRESS更改为运行数据库的服务器

d. Make sure the connection string is similar to: jdbc:sqlserver://localhost\SQLEXPRESS; database=[Database Name]; integratedSecurity = true; where localhost\SQLEXPRESS is changed to the server you are running your database from

这篇关于Java SQL Server 2012无法打开数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆