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

查看:49
本文介绍了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一个.将服务器实例命名为 SQLExpress/SQLEXPRESS湾确保服务器接受混合身份验证方法(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

一个.停止 SQL Server (SQLEXPRESS) 和 SQL Server Browser 服务

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

B.在 SQL Server Network Configuration 下打开 Protocol for SQLEXPRESS 并启用 TCP/IP

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

c.启用所有端口(特别是 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 驱动程序添加到服务中(右键单击  New Driver...)

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

d.确保连接字符串类似于:jdbc:sqlserver://localhostSQLEXPRESS;数据库=[数据库名称];集成安全=真;其中 localhostSQLEXPRESS 更改为您运行数据库的服务器

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

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

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