| Tutorials Main Latest Tutorials Popular Tutorials Top Rated Tutorials | Login to See your Favorite Tutorials |
| Description:
Version: 1.0 Added on: 28 May 2011 Author: David Welford-Costelloe Difficulty Level: Easy Views: 153 | Detailed Profile Rate Resource |
Well let us see if this is the case.
What do we need for this Tutorial?
1.MySQL Database (community addition)
2.WebORB Presentation server for .NET (community addition)
3.Visual Studio 2008 C# - Express edition (free)
4.MySQL Database GUI tools
5.Flash Builder 4 (60 day trial version)
This tutorial will be generated on Microsoft Windows Vista, now let us get down to business.
Download and install these tools:
1.Your choice either C# or VB.NET (I like C#) http://www.microsoft.com/express/Downloads/
2.MySQL Server http://dev.mysql.com/downloads/
3.MySQL GUI Tools http://dev.mysql.com/downloads/gui-tools/5.0.html
4.MySQL connector for .NET http://dev.mysql.com/downloads/connector/net/6.2.html
5.Flash Builder 4 https://www.adobe.com/cfusion/tdrc/index.cfm?product=flash_builder
6.WebORB Presentation server for .NET
http://www.themidnightcoders.com/prod … orb-for-net/overview.html
Install all of the above and make sure you keep the root admin account password handy for MySQL Database. I am fortunate to have a Team developer version of Visual Studio 2008 which I will be using in this demo which is similar to the express version you have downloaded. First off we will build the MySQL Database and Tables:


MySQL Database Configuration
Create a simple database and table to read. Open the MySQL Query Browser part of the MySQL GUI tools installed.
Enter the root password you setup during installation and click OK


Right click the Schema Tab and select Create New Schema (CTRL-N)
Enter DemoSample as the name and click OK:
Right Click demosample Schema and select create Table:

Create the following table and Fields:

Make sure user_id is primary key and Auto Increment.

Click Execute.

Insert the following records:

Sample after insertion:

Build C# Assembly
Open Visual Studio C#:
If you are using Vista make sure you open this as administrator.



Create a new Project (in this demo this is C#)

Select Visual C# and Class Library and name it MySQLDemo and click ok



Rename the Class1.cs to MySQLDemo.cs
1. Add reference to MySQL connector

2.Right click the solution explorer references and Add MySqlData reference
3.Add the following reference MySql.Data
4.Add the following references to your code
using MySql.Data.MySqlClient;
Using MySql.Data.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Data;
namespace MySQLDemo
{
public class MySQlDemo
{
private MySqlConnection myConnection;
private MySqlDataAdapter myDataAdapter;
private DataSet myDataSet;
private string strSQL = String.Empty;
public DataSet getUserInformation()
{
myConnection = new MySqlConnection ("server =localhost; user id=root;password=yourrootpassword; database=demosample; pooling=false;");
strSQL = "SELECT * FROM userlist";
myDataAdapter = new MySqlDataAdapter(strSQL, myConnection);
myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet,"UserList");
myDataAdapter.Dispose();
return myDataSet;
}
}
}
Above is the complete code for the MySQL Database connection, all we are doing is getting the list of records in the table. Compile the DLL as release and deploy to the WebORB Server.


Install WebORB Server
Download the WebORB Server for .NET:
http://www.themidnightcoders.com/prod ... rb-for-java/overview.html
Install the WebORB by following the instructions once completed open a browser and go to:
http://localhost/weborb30
Above will be the screen to show you have successfully installed WebORB. The next item is to deploy the .NET assembly to WebORB. This can be completed two ways:
1.Using the Deployment Tab on the Console
2.Copy the dll to the WebORB bin directory
In this demo we will be using the WebORB console Deployment Tab


Click on the Deployment Tab and select the button ‘Deploy Assembly’


Select the folder where Visual Studio .NET has compiled the assembly

Select Open you will now see the assembly deployed
And that is it for Deploying to WebORB Presentation Server. Next we will build the Flash 4
Using Flex SDK 4.0.

Building Flash Builder 4 Application
This application will need to be configured to use ASP.NET. Each step required will be outlined:

1.Create New Flex Project File ==> New ==> Flex Project

2.Because I also use the Flash Builder 4 for my Flex 3.5 SDK projects I configure the Flex 4 SDK manually:
3.Make sure Application Server Type is set to ASP.NET and click Next

4.On this page we configure the WebORB Server using IIS
5.Check User Internet Information Services (IIS)
6.Web application root: Select Browse to where you installed WebORB virtual directory
7.Web application URL:
http://localhost/weborb30

8.Click Validate Configuration

9.Click Next
10.Click Finished to build the project structure






Now we need to connect to the WebORB server and call the .NET assembly to get our information back from the MySQL Database.
1.Open your browser to
http://localhost/weborb30
2.This time we are going to use the Management Tab to generate the required code for the Flash Builder.



3.Click on the right section MySQLDemo.DLL Expand to getUserInformation
4.Here we are going to test the Assembly DLL to make sure it works. Click on the Invoke button.

5.You can now see the results of the assembly

6.All is well now we will generate the required code for the Flash Builder – Click up one level to generate Code

7.As you can see we now have all the code required.

8.Two action script classes have been generated Click the download button and save the code to a folder:



In my case I saved to DocumentsFlexCode
9.Extract the contents of the zip file:
A folder call MySQLDemo has been created now we need to drag and drop this folder into out Flash Builder project.

10.Drag the folder to the 'src' directory in the project

11.The package MySQLDemo with action script classes has been generated for you

12.Now we will create a simple Datagrid to hold the information from the assembly

13.Click on Source to bind the classes

14.Remove the columns from the grid as these will be auto generated for this demo
<s:HGroup x="238" y="120" width="573" height="280">
<mx:DataGrid id="mydataGrid" width="571" height="279"/>
</s:HGroup>
15.Add the Script tags
<fx:Script>
<![CDATA[
]]>
</fx:Script>
16.Look at the MySQLDemoModel.as code file

17.Copy the highlighted code to the Script section

18.Add a function call getUsersFromMySQL

19.Select serviceProxy.getUserInformation();

20.Set the DataGrid DataProvider to:
dataProvider="{model.getUserInformationResult}"

21.Add creationComplete

22.Set the creationComplete="getUsersFromMySQL()"
23.Now we need to add a parameter to the Flash Builder Compiler to invoke the WebORB configuration. Right Click the project and select properties

24.Select the Flex Compiler

25.In the Additional compiler arguments add the following:

-services c:Inetpubwwwrootweborb30web-infflexservices-config.xml
26.Click OK to save and run the application

I added a little bit of code from Tour De Flex samples to make it more appealing


That is it we have now connected to a .NET assembly and had the assembly connect to MySQL database and return the information to our Flash Builder project. ![]()