in the sync SyncFramework after serverProvision.Apply tablename_tracking table and stored procedure created with server connectionstring DB UID for ex: tasnim_DBUser.tabelname_tracking or tasnim_DBUser.tablename_selectchanges ,...
server connectionstring : #"Data Source=sitedomain,1433;Persist Security Info=false;Initial Catalog=databasename;UID=tasnim_DBUser;PWD=*******;";
I want create with dbo.******
i set ObjectSchema but Is not resolved
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc)
{
ObjectSchema = "dbo",
ObjectPrefix = "dbo"
};
host is shared , Plesk panel
edit 1 :
Server Provisioning Code:
if (new SqlSyncScopeProvisioning(serverConn).ScopeExists("MySyncScope2")) return;
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("MySyncScope2");
DbSyncTableDescription tableNameTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("tableName", serverConn);
.
.
.
scopeDesc.Tables.Add(tableNameTableDesc);
.
.
.
try
{
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
if (!serverProvision.ScopeExists("MySyncScope2")) serverProvision.Apply();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Clint Provisioning Code:
if (new SqlSyncScopeProvisioning(db.Con).ScopeExists("MySyncScope2")) return;
try
{
DbSyncScopeDescription scopeDescClint =
SqlSyncDescriptionBuilder.GetDescriptionForScope("MySyncScope2", serverConn);
SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(db.Con, scopeDescClint);
if (!clientProvision.ScopeExists("MySyncScope2")) clientProvision.Apply();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
i found the solution , db user must have db_owner role and set default schema "dbo" with this query
ALTER USER dbUserName WITH DEFAULT_SCHEMA = dbo;
or in SQL server management studio / security / users / db-username / Right-click / properties / set default schema "dbo"
Related
I'm following the AWS documentation about how to connect to redshift [generating user credentials][1]
But the get-cluster-credentials API requires a cluster id parameter, which i don't have for a serverless endpoint. What id should I use?
EDIT:
[![enter image description here][2]][2]
This is the screen of a serverless endpoint dashboard. There is no cluster ID.
[1]: https://docs.aws.amazon.com/redshift/latest/mgmt/generating-user-credentials.html
[2]: https://i.stack.imgur.com/VzvIs.png
Look at this Guide (a newer one) that talks about Connecting to Amazon Redshift Serverless. https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-connecting.html
See this information that answers your question:
Connecting to the serverless endpoint with the Data API
You can also use the Amazon Redshift Data API to connect to serverless endpoint. Leave off the cluster-identifier parameter in your AWS CLI calls to route your query to serverless endpoint.
UPDATE
I wanted to test this to make sure that a successful connection can be made. I followed this doc to setup a Serverless instance.
Get started with Amazon Redshift Serverless
I loaded sample data and now have this.
Now I attemped to connect to it using software.amazon.awssdk.services.redshiftdata.RedshiftDataClient.
The Java V2 code:
try {
ExecuteStatementRequest statementRequest = ExecuteStatementRequest.builder()
.database(database)
.sql(sqlStatement)
.build();
ExecuteStatementResponse response = redshiftDataClient.executeStatement(statementRequest);
return response.id();
} catch (RedshiftDataException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
Notice there is no cluster id or user. Only a database name (sample_data_dev). The call worked perfectly.
HEre is the full code example that successfully queries data from a serverless instance using the AWS SDK for Java V2.
package com.example.redshiftdata;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.redshiftdata.model.*;
import software.amazon.awssdk.services.redshiftdata.RedshiftDataClient;
import software.amazon.awssdk.services.redshiftdata.model.DescribeStatementRequest;
import java.util.List;
/**
* To run this Java V2 code example, ensure that you have setup your development environment, including your credentials.
*
* For information, see this documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class RetrieveDataServerless {
public static void main(String[] args) {
final String USAGE = "\n" +
"Usage:\n" +
" RetrieveData <database> <sqlStatement> \n\n" +
"Where:\n" +
" database - the name of the database (for example, sample_data_dev). \n" +
" sqlStatement - the sql statement to use. \n" ;
String database = "sample_data_dev" ;
String sqlStatement = "Select * from tickit.sales" ;
Region region = Region.US_WEST_2;
RedshiftDataClient redshiftDataClient = RedshiftDataClient.builder()
.region(region)
.build();
String id = performSQLStatement(redshiftDataClient, database, sqlStatement);
System.out.println("The identifier of the statement is "+id);
checkStatement(redshiftDataClient,id );
getResults(redshiftDataClient, id);
redshiftDataClient.close();
}
public static void checkStatement(RedshiftDataClient redshiftDataClient,String sqlId ) {
try {
DescribeStatementRequest statementRequest = DescribeStatementRequest.builder()
.id(sqlId)
.build() ;
// Wait until the sql statement processing is finished.
boolean finished = false;
String status = "";
while (!finished) {
DescribeStatementResponse response = redshiftDataClient.describeStatement(statementRequest);
status = response.statusAsString();
System.out.println("..."+status);
if (status.compareTo("FINISHED") == 0) {
break;
}
Thread.sleep(1000);
}
System.out.println("The statement is finished!");
} catch (RedshiftDataException | InterruptedException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
public static String performSQLStatement(RedshiftDataClient redshiftDataClient,
String database,
String sqlStatement) {
try {
ExecuteStatementRequest statementRequest = ExecuteStatementRequest.builder()
.database(database)
.sql(sqlStatement)
.build();
ExecuteStatementResponse response = redshiftDataClient.executeStatement(statementRequest);
return response.id();
} catch (RedshiftDataException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
public static void getResults(RedshiftDataClient redshiftDataClient, String statementId) {
try {
GetStatementResultRequest resultRequest = GetStatementResultRequest.builder()
.id(statementId)
.build();
GetStatementResultResponse response = redshiftDataClient.getStatementResult(resultRequest);
// Iterate through the List element where each element is a List object.
List<List<Field>> dataList = response.records();
// Print out the records.
for (List list: dataList) {
for (Object myField:list) {
Field field = (Field) myField;
String value = field.stringValue();
if (value != null)
System.out.println("The value of the field is " + value);
}
}
} catch (RedshiftDataException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
}
I have a GRPC server written on C#.
internal class Program
{
internal static void Main(string[] args)
{
using (var waitHandle = new AutoResetEvent(false))
{
void OnConsoleOnCancelKeyPress(object o, ConsoleCancelEventArgs e)
{
e.Cancel = true;
// ReSharper disable once AccessToDisposedClosure
waitHandle.Set();
}
Console.CancelKeyPress += OnConsoleOnCancelKeyPress;
var config = new AppConfig(new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false)
.Build());
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterModule(new Module());
containerBuilder.RegisterModule(new Data.Module(config.Region, config.TablePrefix));
using (var container = containerBuilder.Build())
{
var buyRatesService = container.Resolve<BuyRatesService>();
var logger = container.Resolve<ILogger<Program>>();
var server = new Server
{
Services =
{
BuyRates.BindService(buyRatesService)
},
Ports = {new ServerPort("0.0.0.0", 50051, ServerCredentials.Insecure)}
};
try
{
server.Start();
logger.LogDebug("Service started");
waitHandle.WaitOne();
}
catch (Exception e)
{
logger.LogCritical("Application terminated unexpectedly. Exception {#exception}", e);
}
finally
{
server.ShutdownAsync().Wait();
Console.CancelKeyPress -= OnConsoleOnCancelKeyPress;
}
}
}
}
}
It works fine locally. I deploy it to ecs instance(Docker). The container port is 50051. ALB and Route 53 are used.
When I'm trying to connect to someroute54uri.net:50051 I get an error
Grpc.Core.RpcException: Status(StatusCode=Unavailable, Detail="Connect Failed").
In case when I'm trying to connect to someroute54uri.net, I get an error
Grpc.Core.RpcException: Status(StatusCode=Unavailable, Detail="Trying to connect an http1.x server").
Thanks!.
Please, let me know if additional information helps to solve the issue.
I am using Jersey REST Webservices for my Application which is like a type of blog website ( means no user registration or authentication are required)
I have some webservices which queries the database and sends the data to the Front End .
As you know the user can see the webservice calls in browser network tab and fire the query manually
My question is , how can i protect sever / Service from being hit continously (for loop written manually to break the application)
This is how my service looks like
#GET
#Produces("text/plain")
public String displaylatestnews() {
String latestnews = "";
PreparedStatement selectpstmt = null;
ResultSet selectRset = null;
Connection conn = null;
String selectsql = "SELECT rssjson from rssfeeds limit 1";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
selectpstmt = conn.prepareStatement(selectsql);
selectRset = selectpstmt.executeQuery();
if (selectRset.next()) {
latestnews = selectRset.getString("rssjson");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
selectRset.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
selectpstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return "jsonCallback(" + latestnews.toString() + ")";
}
You can start avoiding creating a connection to mysql every time there's a request, secondly you can add some sort of caching to start with. Even a cache that only lasts few seconds can save tons of db accesses.
We are looking to push periodic or event driven Glass Timeline updates and we're running into issues with the AuthUtil provided in the Java Glass starter project.
Normally, we would just need to call the following after a user has enabled our app with Google permissions:
Credential credential = AuthUtil.getCredential(googleUserToken);
This works perfectly when retrieving the Google UserToken from an HttpRequest during the authentication servlet or the notification servlet.
We are persisting the user's Google User Token at the App authentication phase. However, the same valid Google UserTokens returns a null Credential object when attempting to get the Google Credential from a Quartz Job or Message Queue.
We have debugged the code and noticed that the AuthUtil is using the ListableMemoryCredentialStore and this store is empty when trying to retrieve a Credential from a Quartz job.
Going to answer my own question here. The AuthUtil helper packaged with the starter project provides only an in-memory cache of Google Credentials. In the event of a server restart or new instance, the cache is gone and the user is then directed to the Google OAuth flow.
To prevent this and provide scalability to your Glass app, use the following CredentialStore implementation and replace the use of the ListableMemoryCredentialStore in AuthUtil. It's not the cleanest, but it's lightweight and preserves the singleton intent of the AuthUtil.
Replace the JDBC paths to your database, schema, username and password for each of the databse helper methods. The Google credential table is nothing more than a four column table storing the userId as the PK, accessToken, resfreshToken and expriationTimeInMillis. Obviously, feel free to adjust the data model as you see fit.
/**
* Created by Dayel Ostraco
* Date: 12/4/13
*
* This extends the Google OAuth2 CredentialStore interface and uses a Database backend to persist Google Credentials
* in a thread safe manner.
*
*/
public class DatabaseCredentialStore implements CredentialStore {
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseCredentialStore.class);
/**
* Lock on access to the database Credential store.
*/
private final Lock lock = new ReentrantLock();
/**
* Stores a Google OAuth2 Credential in the database.
*
* #param userId String
* #param credential Google OAuth2 Credential
*/
public void store(String userId, Credential credential) {
lock.lock();
try {
DatabasePersistedCredential item = findByUserId(userId);
if (item == null) {
item = new DatabasePersistedCredential();
item.store(userId, credential);
create(item);
}
item.store(userId, credential);
} finally {
lock.unlock();
}
}
/**
* Removes a persisted Google Credential from the database.
*
* #param userId String
* #param credential Google OAuth2 Credential
*/
public void delete(String userId, Credential credential) {
lock.lock();
try {
DatabasePersistedCredential item = findByUserId(credential.getAccessToken());
delete(item);
} finally {
lock.unlock();
}
}
/**
* Loads a Google Credential with the contents of the persisted Google Credentials.
*
* #param userId String
* #param credential Google OAuth2 Credential
* #return boolean
*/
public boolean load(String userId, Credential credential) {
lock.lock();
try {
DatabasePersistedCredential item = findByUserId(userId);
if (item != null) {
item.load(userId, credential);
}
return item != null;
} finally {
lock.unlock();
}
}
/**
* Returns all users in the Google Credentials Table
* #return List of all persisted Google authenticated user IDs
*/
public List<String> listAllUsers() {
List<String> userIds = new ArrayList<>();
for(DatabasePersistedCredential credential : findAll()) {
userIds.add(credential.getUserId());
}
return userIds;
}
/****************
* JDBC Methods *
***************/
/**
* Persists a new Google Credential to the database.
*
* #param credential DatabasePersistedCredential
*/
private void create(DatabasePersistedCredential credential) {
Connection connect;
PreparedStatement preparedStatement;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://yourdatabaseurl:3306/schema?user=un&password=password");
preparedStatement = connect.prepareStatement("INSERT INTO GoogleCredential values (?, ?, ?, ?)");
preparedStatement.setString(1, credential.getUserId());
preparedStatement.setString(2, credential.getAccessToken());
preparedStatement.setString(3, credential.getRefreshToken());
preparedStatement.setLong(4, credential.getExpirationTimeInMillis());
preparedStatement.executeUpdate();
} catch (ClassNotFoundException e) {
LOGGER.error("Could not load MySQL Driver.", e);
} catch (SQLException e) {
LOGGER.error("Could not persist DatabasePersistedCredential.", e);
}
}
/**
* Removes a Google credential from the database.
*
* #param credential DatabasePersistedCredential
*/
private void delete(DatabasePersistedCredential credential) {
Connection connect;
PreparedStatement preparedStatement;
ResultSet resultSet;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://yourdatabaseurl:3306/schema?user=un&password=password");
preparedStatement = connect.prepareStatement("DELETE * FROM spgglassdb.GoogleCredential WHERE userId = ?;");
preparedStatement.setString(1, credential.getUserId());
preparedStatement.executeQuery();
} catch (ClassNotFoundException e) {
LOGGER.error("Could not load MySQL Driver.", e);
} catch (SQLException e) {
LOGGER.error("Could not persist DatabasePersistedCredential.", e);
}
}
/**
* Returns the Google credentials for a user with the passed in userId.
*
* #param userId String
* #return DatabasePersistedCredential
*/
private DatabasePersistedCredential findByUserId(String userId) {
Connection connect;
PreparedStatement preparedStatement;
ResultSet resultSet;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jjdbc:mysql://yourdatabaseurl:3306/schema?user=un&password=password");
preparedStatement = connect.prepareStatement("SELECT * FROM spgglassdb.GoogleCredential WHERE userId = ?;");
preparedStatement.setString(1, userId);
resultSet = preparedStatement.executeQuery();
List<DatabasePersistedCredential> credentials = convertResultsSet(resultSet);
if(credentials.size()==1) {
return credentials.get(0);
} else {
return null;
}
} catch (ClassNotFoundException e) {
LOGGER.error("Could not load MySQL Driver.", e);
} catch (SQLException e) {
LOGGER.error("Could not persist DatabasePersistedCredential.", e);
}
return null;
}
/**
* Returns all DatabasePersistedCredentials located in the database.
*
* #return List<DatabasePersistedCredential>
*/
private List<DatabasePersistedCredential> findAll() {
Connection connect;
PreparedStatement preparedStatement;
ResultSet resultSet;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://yourdatabaseurl:3306/schema?user=un&password=password");
preparedStatement = connect.prepareStatement("SELECT * FROM spgglassdb.GoogleCredential;");
resultSet = preparedStatement.executeQuery();
List<DatabasePersistedCredential> credentials = convertResultsSet(resultSet);
return credentials;
} catch (ClassNotFoundException e) {
LOGGER.error("Could not load MySQL Driver.", e);
} catch (SQLException e) {
LOGGER.error("Could not persist DatabasePersistedCredential.", e);
}
return null;
}
/**
* Converts a ResultSet to a collection of DatabasePersistedCredentials.
*
* #param resultSet JDBC ResultSet
* #return List<DatabasePersistedCredential>
* #throws SQLException
*/
private List<DatabasePersistedCredential> convertResultsSet(ResultSet resultSet) throws SQLException {
List<DatabasePersistedCredential> credentials = new ArrayList<>();
while (resultSet.next()) {
DatabasePersistedCredential credential = new DatabasePersistedCredential();
String accessToken = resultSet.getString("accessToken");
String refreshToken = resultSet.getString("refreshToken");
Long expirationTimeInMillis = resultSet.getLong("expirationTimeInMillis");
credential.setAccessToken(accessToken);
credential.setRefreshToken(refreshToken);
credential.setExpirationTimeInMillis(expirationTimeInMillis);
credentials.add(credential);
}
return credentials;
}
}
how to write a rest web service to query data from solr server in java. I have the a java code to query from solr
CommonsHttpSolrServer server = null;
try
{
server = new CommonsHttpSolrServer("http://localhost:8080/solr/");
}
catch(Exception e)
{
e.printStackTrace();
}
SolrQuery query = new SolrQuery();
query.setQuery(solrquery);
query.set("rows",1000);
// query.setQueryType("dismax");
// query.setFacet(true);
// query.addFacetField("lastname");
// query.addFacetField("locality4");
// query.setFacetMinCount(2);
// query.setIncludeScore(true);
try
{
QueryResponse qr = server.query(query);
SolrDocumentList sdl = qr.getResults();
I need to get the same functionality in a web service by taking id as the query parameter.
If you just want to query the id passed as an parameter to the webservice -
String id = "100145";
String url = "http://localhost:8080/solr/core_name"; // core name needed if using multicore support
CommonsHttpSolrServer solrServer;
try {
solrServer = new CommonsHttpSolrServer(url);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "id:"+id);
QueryResponse qres = solrServer.query(qparams);
SolrDocumentList results = qres.getResults();
SolrDocument doc = results.get(0);
System.out.println(doc.getFieldValue("id"));
} catch (Exception e) {
e.printStackTrace();
}