从我的应用程序连接到本地SQL Server 2008

问题描述 投票:0回答:1

我正在为我的朋友数据库类开发一个Android应用程序,我有点陷入困境。我在建立连接时遇到了麻烦。有人可以帮助我吗?我有一个本地数据库,我对MS SQL服务器了解不多。这是信息:

ip = "Ip address"; // i am inserting IPV4 IP of computer in this
        db = "testing";
        un = "xee";
        pass = "1995";
        port = "1433";

    @SuppressLint("NewApi")
    public Connection connectionclass(String user, String password, String database, String server)
    {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        Connection connection = null;
        String ConnectionURL = null;
        try
        {
            Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
            ConnectionURL = "jdbc:jtds:sqlserver://" + ip +":"+port+";"+ "databaseName=" + db + ";user=" + un + ";password="+ password + ";";
        }
        catch (SQLException se)
        {
            Log.e("error here 1 : ", se.getMessage());
        }
        catch (ClassNotFoundException e)
        {
            Log.e("error here 2 : ", e.getMessage());
        }
        catch (Exception e)
        {
            Log.e("error here 3 : ", e.getMessage());
        }
        return connection;
    }
}

我在尝试连接时遇到错误

E/error here 1 :: Network error IOException: failed to connect to /***.***.*.*** (port 1433) from /:: (port 35033): connect failed: ECONNREFUSED (Connection refused)
android sql sql-server database-connection
1个回答
0
投票

用户名/密码是否正确无误?您的SQL Server是否配置为“混合”身份验证模式? https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/change-server-authentication-mode?view=sql-server-2017用户帐户是否有足够的权限来访问数据库?尝试将登录帐户设置为“sysadmin”,这将为其提供最大权限。

检查防火墙(不是它是否是本地数据库)

© www.soinside.com 2019 - 2024. All rights reserved.