2011-11-30 60 views
0

我有使连接到本地SQL Server 2008 R2的问题,SQL Server 2008 R2的连接错误/ Android的

这里是代码:

System.out.println("MySQL Connect Example."); 
      Connection conn = null; 
      String url = "jdbc:jtds:sqlserver://192.168.2.101:1433/INSERTGT"; 
      String dbName = "podmiot"; 
      String driver = "net.sourceforge.jtds.jdbc.Driver"; 


      String userName = "user"; 
      String password = "pass"; 
      try { 
       Class.forName(driver).newInstance(); 
       conn = DriverManager.getConnection(url+dbName,userName,password); 
       System.out.println("Connected to the database"); 
       int duration = Toast.LENGTH_SHORT; 


       Toast.makeText(getApplicationContext(), "Connected to the database", duration); 

       conn.close(); 
       System.out.println("Disconnected from database"); 
       EditText edit1 = (EditText)findViewById(R.id.editText1); 
       edit1.setText("Disconnected from database"); 

      } catch (Exception e) { 
       e.printStackTrace(); 
       TextView edit1 = (TextView)findViewById(R.id.exception); 
       edit1.setText("Problem: " + e.toString()); 
      } 

错误:

当我尝试使连接我得到错误:java.sql.SQLException: Network error IOException: localhost/127.0.0.1:1433 - connection refused.

对不起,我的英语...... :) Thx求救

+0

有可能会阻止该端口上的信息流的防火墙? – hage

+0

no ..防火墙关闭... – rychu151

+0

您可能不希望您的用户名/密码在问题 –

回答

0

您的服务器是否允许远程连接?

http://forums.asp.net/t/1338911.aspx

+0

我不确定,因为我下载了这个程序(sql管理工作室),我甚至不能使用它,因为它写在您的链接...但我也在其他网站上发现了如何在注册表中使用它,并且它看起来像我都很好,:/ – rychu151

+0

这听起来像你可能没有正确的软件。你可以尝试这些链接,以确保你有服务器。管理工作室仅用于连接到服务器。 http://msdn.microsoft.com/en-us/sqlserver/bb671149 – user498023