2011-11-30 38 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

相關問題