How can a client query a db4o server? - client

I've set up a db4o server and client. My client calls are not working.
What's puzzling to me is that the db4o examples show how the client can close the server, but not how to get and save data. See: http://community.versant.com/Documentation/Reference/db4o-7.12/java/reference/Content/client-server/networked/simple_db4o_server.htm
If I start the db4o server, and run netstat, I can see that the port is open. And on the client, I can do things like this:
Debug.WriteLine(db.Ext().IsClosed().ToString());
And that returns False, which is good.
But when I try to get or save data, it doesn't work. When saving data, it appears to work, but I don't see the data in the DB. When trying to retrieve the object, I get this error:
Db4objects.Db4o.Ext.Db4oException: Exception of type 'Db4objects.Db4o.Ext.Db4oException' was thrown. ---> System.ArgumentException: Field '_delegateType' defined on type 'Db4objects.Db4o.Internal.Query.DelegateEnvelope' is not a field on the target object which is of type 'Db4objects.Db4o.Reflect.Generic.GenericObject'.
Here are the client calls to save, then get:
Server server = new Server() { Name = "AppServerFoo" };
IObjectContainer db = GetDatabase();
db.Store(server);
db.Close();
Here's the only line in the GetDatabase() method:
return Db4oClientServer.OpenClient(Db4oClientServer.NewClientConfiguration(), "DellXps", 8484, "user", "password");
And here's the call to get from the DB:
IObjectContainer db = GetDatabase();
Server testServer = db.Query<Server>(server => server.Name == "AppServerFoo").FirstOrDefault();
db.Close();
What am I missing?

Well a server without a reference the persisted classes is a 'risky' thing. A lot of functionally doesn't work and the error which occur are cryptic. I highly recommend to always reference the assembly with the persisted classes on the server.
Another tip: Use LINQ instead of native queries. It works better and has less problems.

A ha! I got it. It took some googling, but the problem was that the server didn't have a reference to the entities. As soon as my server project referenced my client project, it worked. So, it looks like I just need to move my entities to a common project that both the client and server can reference.
Thanks to this link:
http://www.gamlor.info/wordpress/2009/11/db4o-client-server-and-concurrency/
This link looks like a gateway to having the server work without referencing the entities:
http://community.versant.com/Documentation/Reference/db4o-7.12/net2/reference/html/reference/client-server/server_without_persistent_classes_deployed.html

Related

How can I connect to Oracle DB using Sahi 5.0 OS

I'd like to connect to Oracle Database using Sahi 5.0 OS API:
var $db = _getDB($driver, $jdbcurl, $username, $password)
or
var $db = _getDB("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:#dbserver:1521:sid",
"username", "password");
I have downloaded classes12.jar and ojdbc14.jar and put it in C:\Users\Username\sahi\extlib\db
I've also already added in dashboard.bat:
set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;
%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar;
%SAHI_HOME%\extlib\db\ojdbc14.jar;%SAHI_HOME%\extlib\db\classes12.jar
and in dashboard.sh:
SAHI_CLASS_PATH=$SAHI_HOME/lib/sahi.jar:$SAHI_HOME/extlib/rhino/js.jar:
$SAHI_HOME/extlib/apc/commons-codec-1.3.jar:
$SAHI_HOME/extlib/db/ojdbc14.jar:$SAHI_HOME/extlib/db/classes12.jar
However if I try use 1st method to use _getDB i've following result:
Java constructor for "net.sf.sahi.plugin.DBClient"
with arguments "string,string,string,string" not found.
When I use second one I have this:
Java constructor for "net.sf.sahi.plugin.DBClient"
with arguments "string,string,java.util.Properties" not found.
How connect I connect to Oracle DB and use methods like $db.select and $db.update?
I'm working on Windows 7 with JDK 1.8
I think I can help you.
Was also getting errors when trying to connect to a database with Sahi OS.
The examples shown in https://sahipro.com/docs/sahi-apis/database-apis.html page are useful, but I believe there is more to the SAHI Pro.
Because I said it above?
I tried a number of ways and was not loading the database. Another problem is that I was trying to insert and not recover data.
I began to analyze the obtained error (same as yours) and then found that the SAHI API, this class 'net.sf.sahi.plugin.DBClient', there is the constructor method in the class, the _getDb function () calls to start the object.
Concludes that it found the SAHI API available on Github and checked by the class.
There is no method builder, this function does not work for SAHI OS.
So we have to do this using functions of the JAVA language, as is the example: https://sahipro.com/docs/sahi-apis/database-apis.html#Accessing%20databases%20directly
I modified this function (as I said, I was entering in the database) to my need, which was inserted into the database and vualá !!!! It worked!
I used SQLite (the SAHI documentation contains no example)
To clarify, the function I created would be this:
function setRawDB(driverName, jdbcurl, sqlQuery) {
java.lang.Class.forName(driverName);
var connection = java.sql.DriverManager.getConnection(jdbcurl);
var stmt = connection.createStatement();
var query = stmt.executeUpdate(sqlQuery);
stmt.close();
//sahi auto commit
//connection.commit();
connection.close();
}
and then I got to use automated scripts (before I was just getting used testing directly on the page), saving directly in the local database.
Only in this way could use.

Setting UUID manually

My server generates UUID for uploaded files, so i need to set UUID to the fileState after i received answer from upload server (to successfully use delete function). I added and implemented
setUuid: function(id, uuid)
In UploadHandler, FineUploaderBasic and UploadHandlerXhr to solve this issue but this involve editing fine-uploader sources, is there any other way around? I have feeling this can break something internally.
I would suggest not passing the UUID back to fine uploader. It would be simpler to associate your UUID with fine uploader's UUID server side. You could maintain a map of associations in the session if you don't want to persist them.
I encountered this issue and found some documentation that states you can set the UUID from the server side by returning it from the upload method.
click image where newUuid is being set
Here is my return method using C#
return new FineUploaderResult(true, new { newUuid = attachmentId });

Mondrian olap - DriverManager.getConnection error

In my gwt web-app i'm using Mondrian. I have a method:
private Result executeMdxQuery(String queryString, Schema schema) throws InterruptedException {
CatalogLocatorImpl locator = new CatalogLocatorImpl();
Connection mdxConnection = DriverManager.getConnection(createConnectString(schema), locator);
return executeMdxQuery(queryString, mdxConnection);
}
result of createConnectString(schema) is
Provider=mondrian;Jdbc=jdbc:mysql://localhost/dds?user=root&password=qwerty;Catalog=/home/vskovalenko/schemas/air_new_zealand_monthly_traffic.xml;JdbcDrivers=com.mysql.jdbc.Driver;
all data within it is seems to be correct (at least db credentials and path to the file), this method throws no exception, it just silently dies and doesn't tell anything. Where should i loock to?
You should use the olap4j API to get a connection. This will allow you to let the application server manage and pool the connections to Mondrian.
If you require more control on the Mondrian server instance, you should take a look at the class MondrianServer.
add the following snippet to your code and try again:
Class.forName("mondrian.olap4j.MondrianOlap4jDriver");

How to reference an initialized embedded RavenDB instance in a Class Library?

My scenario is this:
I have a custom RavenDB membership provider that is implemented in a class library (DLL). This provider needs to access a database to store and retrieve User and Role information. I'd like to use the same app database to store membership information to avoid having one more database.
I don't know how to get a reference to the already initialized database (app database) inside the class library code. I think I'm going the wrong way here... :)
Some code:
bool embeddedStore = Convert.ToBoolean(config["enableEmbeddableDocumentStore"]);
if (embeddedStore)
{
_documentStore = new EmbeddableDocumentStore()
{
// Here I'm using the same connection string used by the app.
// This gives me an error when I try to open a session in the DocumentStore.
ConnectionStringName =
config["connectionStringName"]
};
}
else
{
_documentStore = new DocumentStore()
{
ConnectionStringName =
config["connectionStringName"]
};
}
This is the connection string present in Web.config:
<add name="RavenDB" connectionString="DataDir = ~\App_Data\Database" />
How can I reuse the same database within the custom membership provider? Any ideas?
I thought about moving the class library code files to the Web project. This way I could get a reference to the DocumentStore easily, but the code wouldn't be as organized as I'd like.
I also tried to use 2 RavenDB databases: 1 for the app and 1 for the membership provider, but as I'm running RavenDB in its embeddable fashion I couldn't get it working.
These are the errors I got during my attempts so far:
RavenDB Could not open transactional storage.
Temp path already used by another database instance.
You need to pass the instance of the opened document store to your dll.
You can do that using a container or by providing an API call to do that.
You can't have two instance using the same db.

First try wcf data service always times out from client

I have read all other posts and have been googling this for the last 2 hours! I started WCF Data Services about 3 hours ago btw.
My service is on an asp.net4 app, the ado entity model exposes an sql server db.
Here is FasDataService.svc.cs
public class FasDataService : DataService<FASStoreEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config.UseVerboseErrors = true;
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}
I have then a winforms 4 app with the following code in the Main()
FASStoreEntities fas = new FASStoreEntities(u);
var a = from al in fas.Customers
where al.Name == "Alinio"
select al;
MessageBox.Show(a.First().Phone1);
When I run the web app and point to http://localhost:15995/FasDataService.svc/Customers(1) it loads up the one and only customer in there
My error is WebException was unhandled:
The operation has timed out. The inner
exception is null.
Also, everything is local but when I do this (in chrome) it takes a good load of time! Its scary to think of how it would perform in production?
For some reason, today I installed fiddler and tried it and it works! I also, queried the service with linqpad and it worked no prob!
Although throughout today I played with wcf data services and had tons of problems accessing data because of all kinds of errors, data connection was still open, some error insert excess data in a field etc etc.
Fiddler was very helpful at diagnosing what the error was, its very difficult to figure out what really went wrong so fiddler is a must have.

Resources