Friday, August 30, 2013

Could not perform FindAll() for (Model) using ActiveRecordBase in Castle.ActiveRecord ORM

When running a simple asp.net mvc project, I encountered an error which states the Model.FindAll() could not be performed. Model is a class that maps to a database table. After tracing my codes, I found out that I have mispelled the database name in my web.config as specified below:
 <add key="connection.connection_string" value="Data Source=MyComputerStation\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Blogs.mdf;Integrated Security=True;User Instance=True"/>  
What I did was change the database name from Blogs to Blog.

That's it! :)

Greg

Wednesday, August 28, 2013

Set connection string through Properties.Settings in ASP.NET Class Library Project

Usually, we set an asp.net connection string directly in the app.config. However, we can also do it Properties.Settings. As soon as we saved the name and value, it will reflect in the app.config. Here's a sample image as reference:

Cheers!

Monday, August 19, 2013

Pass By Reference not allowed in UI threading

The code below does not allow pass by reference to be used in UI threading
particularly method Invoker.
Code:
  private void ShowPassMeta(ref int passedSound)  
  {  
       if (lblPassSoundex.InvokeRequired)  
       {  
            lblPassSoundex.Invoke((MethodInvoker)delegate  
            {  
                 ShowPass(ref passedSound);  
            });  
       }  
       else  
       {  
            lblPassSoundex.Text = (++passedSound).ToString();  
       }        
  }

The solution is to store the method parameter in another variable as shown below:
Code:
  private void ShowPassMeta(ref int passedSound)  
  {        
    var passedSound1 = passedSound;  
    if (lblPassSoundex.InvokeRequired)  
    {  
      lblPassSoundex.Invoke((MethodInvoker)delegate  
      {  
        ShowPassMeta(ref passedSound1);  
      });  
    }  
    else  
    {  
      lblPassSoundex.Text = (++passedSound1).ToString();  
       }  
  }
Cheers!