I am using SQL Server to connect to the database. But, I receive this error when I attempt to connect.
Code for connecting database
ConnectionConfig connectionConfig = new ConnectionConfig();
Connection con = connectionConfig.CONN();
The error produces by Log
Cannot open database "FBMain" requested by the login. The login failed.
Here is the code
public class ConnectionConfig {
private String ip = "192.168.56.1";
private String classs = "net.sourceforge.jtds.jdbc.Driver";
private String db = "FBMain";
private String un = "sa";
private String password = "Password123";
@SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL;
try {
Class.forName(classs);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (Exception e) {
Log.e("ERROR", e.getMessage());
}
return conn;
}
}
I have checked the user mappings for user sa. The database role membership for FBMain is set to db_owner and public. But, I can't connect at all.