This is an issue that has really been killing me, so I figured I would take it to you fine gentlemen/women to see if we can get a solution.
这是一个真正杀了我的问题,所以我想我会把它带给你很好的绅士/女人,看看我们是否能得到解决方案。
I am trying to connect to a SQL server 2005 (MSSQLSERVER, not SERVEREXPRESS or anything like that) I have set up on a machine running Windows Server from my labtop. My labtop is using a java connection string with JDBC 4.0 (via Netbeans IDE) JDK 1.7. It uses windows authentication. The connection code is the following:
我正在尝试连接到SQL Server 2005(MSSQLSERVER,而不是SERVEREXPRESS或类似的东西)我已经在运行Windows Server的机器上设置了我的labtop。我的labtop使用Java连接字符串和JDBC 4.0(通过Netbeans IDE)JDK 1.7。它使用Windows身份验证。连接代码如下:
String url;
url = "jdbc:sqlserver://[Server IP Address]\\[Instance Name]:1433;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);
Instance name = UB-TCMG Note: After [Server IP Address] there are two backslashes. If there is only one backslash, it is counted as an escape character. Two seems to only count as one.
实例名称= UB-TCMG注意:在[服务器IP地址]之后有两个反斜杠。如果只有一个反斜杠,则将其视为转义字符。两个似乎只算作一个。
Unfortunately, I don't have the error with me at this moment. Basically, it said "Connection refused: connection"
不幸的是,我此刻没有错误。基本上,它说“连接被拒绝:连接”
On the server side, I have done the following based upon online research. Enabled the TCP/IP port in SQL Server Configuration Manager. Erased all Dynamic TCP Ports. TCP Ports are 1433. VIA is enabled.
在服务器端,我基于在线研究完成了以下工作。在SQL Server配置管理器中启用TCP / IP端口。删除所有动态TCP端口。 TCP端口为1433.启用了VIA。
As well, surface area connection has been used to activate the SQL browser.
同样,表面区域连接已用于激活SQL浏览器。
Using telnet from the laptop does not allow any connection. Using telnet on the server works when: telnet [Server Instance Name] 1433
从笔记本电脑使用telnet不允许任何连接。在服务器上使用telnet时:telnet [服务器实例名称] 1433
Both firewalls have been shut off.
两个防火墙都已关闭。
logs say "Server is listening on [ 'any' 1433]"
日志说“服务器正在监听['任何'1433]”
There's more I tried to solve this issue, but I'm literally falling asleep and can't remember. Anything you can suggest to help would be great.
还有更多我试图解决这个问题,但我真的睡着了,不记得了。你可以建议任何帮助都很棒。
3 个解决方案
#1
1
This is the way how you will do connection in Java
这是您在Java中进行连接的方式
import java.sql.*;
public class testConnection
{
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect(
"jdbc:jtds:sqlserver://localhost:1433/tempdb","sa","");
}
}
class DB
{
public DB() {}
public voidn dbConnect(String db_connect_string,
String db_userid, String db_password)
{
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
This article might help please visit this link: http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html
本文可能有所帮助,请访问此链接:http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html
#2
1
Found the solution.
找到了解决方案。
The problem was two-fold. One, my laptop was accessing the internet via a static IP address. When I changed it to dynamic, I was able to connect to the server via land-line using a derivative of the above connection string.
问题是双重的。一,我的笔记本电脑通过静态IP地址访问互联网。当我将其更改为动态时,我能够使用上述连接字符串的派生通过陆线连接到服务器。
The second problem has to do with the network I am using. For some reason, it blocks wireless access to the server. This is something I will resolve with the IT of the network. Still, I can access it through land-line since the IT has not blocked the relevant ports/addresses.
第二个问题与我正在使用的网络有关。出于某种原因,它会阻止对服务器的无线访问。这是我将通过网络IT解决的问题。不过,由于IT没有阻止相关的端口/地址,我可以通过固定电话访问它。
#3
0
Try this might work for You..
试试这可能对你有用..
String connectionUrl = "jdbc:sqlserver://localhost;databaseName=dbname;user=uname;password=pass";
#1
1
This is the way how you will do connection in Java
这是您在Java中进行连接的方式
import java.sql.*;
public class testConnection
{
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect(
"jdbc:jtds:sqlserver://localhost:1433/tempdb","sa","");
}
}
class DB
{
public DB() {}
public voidn dbConnect(String db_connect_string,
String db_userid, String db_password)
{
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
This article might help please visit this link: http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html
本文可能有所帮助,请访问此链接:http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html
#2
1
Found the solution.
找到了解决方案。
The problem was two-fold. One, my laptop was accessing the internet via a static IP address. When I changed it to dynamic, I was able to connect to the server via land-line using a derivative of the above connection string.
问题是双重的。一,我的笔记本电脑通过静态IP地址访问互联网。当我将其更改为动态时,我能够使用上述连接字符串的派生通过陆线连接到服务器。
The second problem has to do with the network I am using. For some reason, it blocks wireless access to the server. This is something I will resolve with the IT of the network. Still, I can access it through land-line since the IT has not blocked the relevant ports/addresses.
第二个问题与我正在使用的网络有关。出于某种原因,它会阻止对服务器的无线访问。这是我将通过网络IT解决的问题。不过,由于IT没有阻止相关的端口/地址,我可以通过固定电话访问它。
#3
0
Try this might work for You..
试试这可能对你有用..
String connectionUrl = "jdbc:sqlserver://localhost;databaseName=dbname;user=uname;password=pass";