I am getting the following SQLServer exception after trying to establish connection: The server principal "SQLServer" is not able to access the database "TMO" under the current security context.
Here's my code:
public java.sql.ResultSet dbConnect(String db_connect_string,
String db_userid,
String db_password,
String query)
{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(db_connect_string,
db_userid, db_password);
System.out.println("connected");
Statement statement = conn.createStatement();
String queryString = query;
ResultSet rs = statement.executeQuery(queryString);
/*while (rs.next()) {
System.out.println(rs.getString(1));
}*/
return rs;
} catch (Exception e) {
e.printStackTrace();
return null;
}
and this is where I call this class:
String query = "select TOP 45000 MEMO_MANUAL_TXT,RAND() from TMO.dbo.merged_memo where MEMO_MANUAL_TXT <> 'CCIH_NULL' and MEMO_MANUAL_TXT not like '%QuikView%' order by RAND()";
ConnectMSSQLServer connServer = new ConnectMSSQLServer();
java.sql.ResultSet m_ResultSet = connServer.dbConnect("jdbc:sqlserver://localhost", "SQLServer",
"****", query);
I am using SQLServer 2008R2 on a Windows Server 2008 R2 OS machine