Sunday, December 04, 2005

@@Identity Equivalent in MySql - Getting Last Inserted ID in MySQL

As a .NET Developer i really get used to Sql Server until I got a small project that require me to developed with MySql database backend. The first thing that I face with is to figure out the equivalent of @@Identity in MySql, got it , LAST_INSERT_ID() in MySql.

The second problem is how to return that function value to the application from the database. Since i am using a straight SQL. Then it turns out that below is my solution. I use execute scalar to retrieve the value of the last inserted id and use the usual executeNonQuery for update. Done.

Example:


comm = New MySqlCommand

param = New MySqlParameter("?MemberID", MySqlDbType.Int32)



If _MemberID = 0 Then

comm = New MySqlCommand("Insert Into Member(FirstName,MiddleName,LastName) VALUES (?FirstName,?MiddleName,?LastName);SELECT LAST_INSERT_ID();")

Else

comm = New MySqlCommand("Update Member( SET FirstName = ?FirstName,MiddleName = ?MiddleName,LastName = ?LastName) WHERE MemberID = ?MemberID; ")

End If

param.Direction = ParameterDirection.Input

comm.Parameters.Add(param)

comm.Connection = conn

With comm.Parameters

.Add(param)

param = New MySqlParameter("?FirstName", MySqlDbType.String)

param.Value = _FirstName

.Add(param)

param = New MySqlParameter("?MiddleName", MySqlDbType.String)

param.Value = _MiddleName

.Add(param)

param = New MySqlParameter("?LastName", MySqlDbType.String)

param.Value = _LastName

.Add(param)
conn.Open()

If _MemberID = 0 Then

_MemberID = comm.ExecuteScalar()

Else

comm.ExecuteNonQuery()

End If

conn.Close()

Tuesday, November 29, 2005

VS 2005 Professional - Unexpected error while loading DXCore

I just finished installing the VS 2005 Professional Edition. Just when i fired up the application an error box pops up.

Unexpected error while loading DXCore

Could not load file or assembly file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50215/mscorlib.dll or one of its dependencies. The system cannot find the file specified.
Type: System.IO.FileNotFoundException
Source: mscorlib
Target Site: nLoad
Call Stack:
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at DevExpress.CodeRush.Proxies.AssemblyLoader.LoadFrom(String assemblyFile)
at DevExpress.CodeRush.Proxies.AssemblyLoader.LoadFrom(String assemblyFile)
at DevExpress.CodeRush.StructuralParser.AssemblyTypesLoader.LoadCoreAssembly(FrameworkVersion version)
at DevExpress.CodeRush.StructuralParser.AssemblyModelCache.LoadCoreAssembly(FrameworkVersion version)
at DevExpress.CodeRush.StructuralParser.ProjectElement.get_SourceModel()
at DevExpress.CodeRush.StructuralParser.ProjectElement.AddReference(AssemblyReference assembly)
at DevExpress.CodeRush.StructuralParser.ProjectElement.LoadAssemblyReferencies(Project project)
at DevExpress.CodeRush.StructuralParser.ProjectElement.LoadProject(Project project)
at DevExpress.CodeRush.StructuralParser.SolutionElement.AddProject(Project project)
at DevExpress.CodeRush.StructuralParser.SolutionElement.LoadSolution(Solution solution)
at DevExpress.CodeRush.Core.SourceModelServices.InitializeService(InitializeCause cause)
at DevExpress.CodeRush.Core.ServiceManager.InitializeAll(InitializeCause cause)
at DevExpress.CodeRush.Core.CodeRush.InitializeCodeRush(DTE applicationObject, AddIn addInInstance, ext_ConnectMode connectMode)
at DevExpress.CodeRush.Shell.AddInShell.LoadDXCore(ext_ConnectMode connectMode)
OSVersion: Win32NT, 5.1.2600.131072
VSVersion: 8.0, Professional

Finally, I identified the problem. It turns out that I have uninstall the Refactor VB 2005 Beta 2 that I installed last time. After I uninstall it, then VS 2005 running smootly.

There is a new version of the refactor VB 2005 http://www.devexpress.com/vbrefactor/

.NET ROCKS!

Thursday, September 08, 2005

.NET Rocks ! High demand for .NET developer

Its good to know that .NET technologies are rocketing!
Check out the links!
http://www.computerworld.com.au/index.php/id;1053966028;fp;16;fpid;0

Saturday, July 30, 2005

ASP.NET 2.0 Callbacks Sample - Inject server controls on the fly without post-back using ASP.NET 2.0 Callbacks

I just added a sample application to my web site.


This sample will demonstrate how we can inject new server controls to a page dynamically without the whole page refresh. Implemented using the ASP.NET 2.0 Callbacks scripts (XMLHTTP).

Please feel free to send me email or comment regarding the sample.

Thursday, July 21, 2005

style.top = 85 doesn't work in Firefox

I spend abour 35 minutes this morning to figure about why element.style.top doesn't work in firefox 1.04. The code is simple, its basically assinging an integer value to the element style top.

el.style.top = 85;

it doesn't work in firefox. Finally, I solved this problem by :

el.style.top = 85 + 'px';

Jobs done !

Sunday, July 10, 2005

Setting up Load Test repository VS 2005

Just a short hint before we can run a load test. Load test requires us to setup a repository. The script for creating the database is stored in
\Microsoft Visual Studio 8\Common7\IDE\loadtestresultsrepository.sql

Once the repository is created then point the admin test controller to load repository to the created database. To do that, Go to Test > Administer Test Controllers ...

Then away you go ...

Saturday, July 09, 2005

Web Test and Load Test in VS 2005

For the last two days I explored the testing features on the VS 2005, mainly the web test and the load test features. There is still no much help provided on this test feature, but the best I could get is from the beta library http://whidbey.msdn.microsoft.com/library/default.asp under Visual Studio Team System > Team Test.

Web Test
Now, what can we do with the web test ?
Basically VS allow us to record the steps that we do on the internet explorer and it will be able to replay it. The things that it records is the HTTP request and the query string parameters. What's the advantage of recording it ? is Automated Piloting. Combining it with load test you can simulate several users doing the same things with what you've recorded. Let's imagine a shopping site.
When we go to display all the products, clicking on a specific product to display its details, all of these steps can be recorded and be played back !

Customisation features of the Web Test :

  • You can also add a pre and post request bycreating a class that inherits from the WebTestPlugin
  • Add a validation
  • Add a rule

That's a brief information on the web test.

Load Test

Web Test in it self won't be much meaningful, the power lies when we add the web test to a load test. You can simulate anynumber of contanst number of user or gradually increase number of user piloting the web sites just as you've recorded on the web test.

What are the things that you can customized?

  • Number of users
  • Portion of browser that is used by the user (for example, 45% IE 5.5, 45% IE 6 and 10% Netscape 6.0)
  • Line connection that the user use (start from Modem 28.8k to high speed connection)
  • and others.

What information can you pull out from the load test ? the answer is a lot!

  • Server based performance counter like available memory on the server, CPU utilization, etc.
  • Page based information, such as response time, etc.
  • File by file information, like response time for accessing each file.
  • Request information
  • heaps more...

And guess what is all come with graph like in the performance counter !

I have a post on how to setup the respository for the load testing.

Wednesday, July 06, 2005

VS 2005 Beta 2 VS 2003 Side by Side = Stable !

I have started developing an ASP.NET 2.0 application for about a month. Surprisingly, the beta 2 has turn out to be very stable, apart from a small thing that I got to get used to. Like, when I double clicking on the vb.file to bring up the code on the solution explorer, or saving all files using ctrl-shift-s, sometimes it crashes. So, to get around this problem I click on the view code or saving a single file instead. The compilation time is quite fast, even though the code editor and debugger still seems a bit slow.
Just as info, I have been running it side by side with VS 2003 and a local SQL 2000 instance, and everything go smooth... I got a few crashes each day, about 5 to 10 times on the average, which I think is not bad at all. Overall it’s worth to start developing in ASP.NET 2.0.

Monday, July 04, 2005

alive and kickin !

Finally after days researching for the best blog provider I decided to have my blog on Blogger. Thanks to Blogaholix http://82.69.12.18/blogaholix/blogaholixfreeservices.htm for helping me on my final decision :)