connecting to two database?

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

alvin3343
Posts: 80
Joined: 24 Jan 2006, 09:37

connecting to two database?

Postby alvin3343 » 15 Mar 2006, 05:11

Hi Lapo,

My client app has to connect to two databases.
One is remote and another is local.
My situation is when client app is started ,
it has to send user's name and pass to a remote database to check
if this user is a registered one.
If this user is already registered then the server extension auto
login this user .
And the user's records during playing are recorded into local database where
sfs is runnig.

The remote SQL server I used is SQL2000 running on win2003
and the local server which sfs is running is win2003 too.
The version of sfs is pro 1.4b3.

Any suggestion?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Mar 2006, 13:42

Hi,
at the moment each zone can setup only one connection to a database and w e usually recommend to use only one whenever possible. This helps in saving resources and keeping your application simpler.

By using a Java extension it would be pretty simple to access other databases. I will experiment a little with the current AS 1.0 framework and see if it's possible to do it in Actionscript too.

I will let you know :)
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Mar 2006, 14:30

Okay, I've inspected the framework and it's definitely easy to setup new connections. 8) Here's how to do it.

You can access an object called __db.DbManager which will create a new connection to a new database.

Here's an example of how to setup a new connection:

Code: Select all

function testDB()
{
   var driverName = "org.gjt.mm.mysql.Driver"
   var connString = "jdbc:mysql://localhost:3306/myDatabase"
   var usrName = "login"
   var pword = "password"
   var connName = "myDbConnection"
   var maxActive = 10
   var maxIdle = 10
   var exhaustedAction = "fail"
   var blockTime = 5000
   
   dbase2 = new __db.DbManager(   driverName,
                           connString,
                           usrName,
                           pword,
                           connName,
                           maxActive,
                           maxIdle,
                           exhaustedAction,
                           blockTime
                        )
   
   var sql = "SELECT nick,pass FROM users ORDER BY nick"      
      
   var queryRes = dbase2.executeQuery(sql)
   
   // etc... etc...
}


As you can see the constructor takes the same exact parameters that you would normally specify in the <DatabaseManager> block of the server config file.

You can find more info about those paramaters here > http://www.smartfoxserver.com/docs/docP ... ection.htm

Finally, make sure to destroy the dbase2 variable in the destroy() method of your extension to release the resource, once it's not needed.

Hope it helps :)
Lapo

--

gotoAndPlay()

...addicted to flash games
alvin3343
Posts: 80
Joined: 24 Jan 2006, 09:37

Postby alvin3343 » 16 Mar 2006, 00:12

Thank you ,I'll try it now.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 46 guests