<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem"> <head><title>Client-Server</title> <script type="text/javascript">/* <![CDATA[ */ window.onload = function(){ var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf'; ZeroClipboard.setMoviePath(pathToFlash); function bindToClipBord(element,content){ var clip = new ZeroClipboard.Client(); clip.setText(content); clip.glue(element); }; if(location.protocol==='file:'){ $('.copylink-marker').remove(); } else{ $('.copylink-marker').each(function(){ var text = $(this).parent().parent().children('.prettyprint').html(); $(this).hover(function(){ bindToClipBord(this,text); }, function(){}); }); } prettyPrint(); }; /* ]]> */</script> <link href="SkinSupport/MadCap.css" rel="stylesheet" /> <link href="Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" /> <script src="Resources/Code/prettify.js"> </script> <script src="Resources/Code/lang-vb.js"> </script> <script src="Resources/Code/jquery.min.js"> </script> <script src="Resources/Code/ZeroClipboard.js"> </script> <script src="SkinSupport/MadCapAll.js" type="text/javascript"> </script> </head> <body> <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../index_CSH.html#client-server.htm" style="">Open topic with navigation</a> </p> <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><span class="MCBreadcrumbs">Client-Server</span> </div> <p> <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">'); document.write("Direct Link"); document.write('</a>');/*]]>*/</script> </p> <p> </p> <h1><a name="kanchor60"></a>Client-Server</h1> <p>db4o's is an embedded database which usually runs in process. Nevertheless db4o also supports a client server setup. There's no ready to use db4o server, instead you embedded the db4o server in a regular application. This gives you full how you want to run the db4o server.</p> <p>In order to use the db4o client server mode you need to include the <span>Db4objects.Db4o.CS.dll-assembly </span>in your project. <a href="dependency_overview.htm" target="" title="" alt="" class="MCXref" xrefformat="See "{paratext}"">See "Dependency Overview"</a></p> <h2>Start The Server</h2> <p>You start the server by creating a object server instance with the client server factory. Pass the database file path and the port to the factory. After that you need to specify a user-name and password which clients can use to login to this server. You can add multiple users by calling the grant access method multiple times.</p> <div class="codesnippet" MadCap:conditions="Primary.c#"> <pre class="prettyprint" xml:space="preserve">using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", 8080)) { server.GrantAccess("user", "password"); // Let the server run. LetServerRun(); }</pre> <div class="codesnippet-meta">ServerExample.cs: Start a db4o server <div class="codedownload"><a href="CodeExamples/clientserver/basics/Example-clientserver-basics-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div> </div> <div class="codesnippet" MadCap:conditions="Primary.VB.NET"> <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Using server As IObjectServer = Db4oClientServer.OpenServer("database.db4o", 8080) server.GrantAccess("user", "password") ' Let the server run. LetServerRun() End Using</pre> <div class="codesnippet-meta">ServerExample.vb: Start a db4o server <div class="codedownload"><a href="CodeExamples/clientserver/basics/Example-clientserver-basics-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div> </div> <h2>Connect To The Server</h2> <p>After the server is up an running you can connect to it. Pass the URL, port, user name and password to the client server factory. This will return a client object container. After that the container is ready to use.</p> <div class="codesnippet" MadCap:conditions="Primary.c#"> <pre class="prettyprint" xml:space="preserve">using (IObjectContainer container = Db4oClientServer.OpenClient("localhost", 8080, "user", "password")) { // Your operations }</pre> <div class="codesnippet-meta">Db4oClientExample.cs: Connect to the server <div class="codedownload"><a href="CodeExamples/clientserver/basics/Example-clientserver-basics-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div> </div> <div class="codesnippet" MadCap:conditions="Primary.VB.NET"> <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">' Your operations Using container As IObjectContainer = Db4oClientServer.OpenClient("localhost", 8080, "user", "password") End Using</pre> <div class="codesnippet-meta">Db4oClientExample.vb: Connect to the server <div class="codedownload"><a href="CodeExamples/clientserver/basics/Example-clientserver-basics-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div> </div> <p> </p> <script type="text/javascript" src="SkinSupport/MadCapBodyEnd.js"> </script> </body> </html>