Friday, August 12, 2011

Visual Studio LightSwitch 2011

The newest addition to the Visual Studio family has arrived. Visual Studio LightSwitch 2011
can build business applications for the desktop and the cloud easily - regardless of your
development skills.
 
Visual Studio LightSwitch 2011 is a development tool that helps you build business applications
quickly. LightSwitch provides a simplified development environment that enables you to
concentrate on the business logic instead of the application infrastructure.
Most business applications are forms-over-data applications that provide a UI for viewing,
adding, and modifying data. When you use other development tools to build forms-over-data
applications, much of your time is spent on repetitive tasks. You write code to interact with a
database, you write code for the user interface, and you write code for the business logic.
When you use LightSwitch, much of the repetitive work is done for you and, in fact, you can
create a LightSwitch application without writing any code at all! For most applications, the
only code you have to write is the code that only you can write: the business logic.  

Features of Business Applications

Data Entities and Screens

Data Validation, Testing, and Deployment   

get more information about Visual Studio LightSwitch from microsoft at this link:

Tuesday, August 9, 2011

BeginInvoke() and EndInvoke()

BeginInvoke() call methods without really knowing when it is finished. But with EndInvoke(),
it is possible to do a few more things. First of all,
EndInvoke will block until your function
 completes execution; so, calling
BeginInvoke followed by EndInvoke is really almost like
calling the function in a blocking mode (because the
EndInvoke will wait until the function
completes). But, how does the .NET runtime know how to bind a
BeginInvoke with an
EndInvoke? Well, that’s where IAsyncResult comes in. When calling BegineInvoke,
the return object is an object of type
IAsyncResult; it is the glue that allows the framework
 to track your function execution. Think of it like a little tag to let you know what is going on
 with your function. With this little powerful super tag, you can find out when your function
 completes execution, and you can also use this tag to attach any state object you might want
 to pass to your function. Okay! Let’s see some examples so this doesn't become too confusing
... Let's create a new function.

private void WaitForOneSecond()

{

    // sleep for one second!

    Thread.Sleep(1000);

}


private void UsingEndInvoke()
{
    // create a delegate of MethodInvoker poiting to our Foo function.
    MethodInvoker methodInvokeDelegate = new MethodInvoker(WaitForOneSecond);
 
    // start FooOneSecond, but pass it some data this time!
    // look at the second parameter
    IAsyncResult tag =
        methodInvokeDelegate.BeginInvoke(null, "passing some state");
 
    // program will block until FooOneSecond is complete!
    methodInvokeDelegate.EndInvoke(tag);
 
    // once EndInvoke is complete, get the state object
    string strState = (string)tag.AsyncState;
 
    // write the state object
    Trace.WriteLine("State When Calling EndInvoke: "
        + tag.AsyncState.ToString());
}

 

Thursday, August 4, 2011

Problem in restoring database in User Instance , "Exclusive Access could not be obtained because the database is in use","Restore a db when the db is in use"

I have made backup of database using SMO very well but when I tried to restore that
 database from that created backup file.  The error I kept getting was:
Restore failed for Server 'localhost\SQLExpress'.
Additional Information that I got in inner exception:
 {"System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the
 database is in use."}

The above line should look familiar to anyone who has done a Database Restore and is
easily solved if you are using Management single user mode command and the restore
command as one query.  Something like:

ALTER DATABASE  [your_db_name] SET SINGLE_USER WITH ROLLBACK
IMMEDIATE

RESTORE DATABASE [your_db_name] FROM  DISK =
N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\your_db_name.bak'
WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10
GO

Syntax is something like that:
use master
go

alter database <dbname> set single_user with rollback immediate
alter database <dbname> set multi_user
you can obtain this using SMO, May be management studio do the restore operation
in single user mode internally, but SMO(server management objects) failed to restore
when database in use. Here is some lines that help to do
database backup successfully. To achieve this just kill the database associated process
before restore operation as:
    Restore restore = new Restore();
    restore.Database = databaseName;
    restore.Devices.AddDevice(backupFileName, DeviceType.File);
    restore.ReplaceDatabase = true;
    _server.KillAllProcesses(databaseName);
    restore.Wait();
    restore.SqlRestore(_server);
..
It may be the solution. try this before the restore statement if you do not want to another database
connected process. It works in my case.
database = new Microsoft.SqlServer.Management.Smo.Database(server, databaseName);
database.Refresh();
databaseOptions = database.DatabaseOptions;
databaseOptions.UserAccess =
                            Microsoft.SqlServer.Management.Smo.DatabaseUserAccess.Restricted;
databaseOptions.Alter(
 Microsoft.SqlServer.Management.Smo.TerminationClause.RollbackTransactionsImmediately);
server.ConnectionContext.SqlConnectionObject.ChangeDatabase("Master");



Sunday, July 31, 2011

Data binding object does not update on Control EditValue Change

Here case is that a binding source have datasource as class object and the properties of that
object is binded with the winform controls. there datasource is not updating on the controls value
change.
Solution:
look into setting (DataBindings)\(Advanced)\Data Source Update Mode to OnPropertyChanged
in the properties for the binding. By default, this is set to OnValidation which means the data source
 is updated as part of the Windows Forms Control validation process when a control is exited
(or when you call EndEdit to force this to happen earlier). (For rows being newly added,
you will still need an EndEdit at some point to actually get the DataRow into the DataTable. 
But at least the in-memory data for the DataRow will be updated earlier.)
When you try to update the object then Validating event fire if it successes then the object update.
so select your update mode according to your requirment.

Thursday, July 28, 2011

BlogEngine.NET open source projects for .NET, great learning source for developers

There are few open source projects available which help to learn more in creating blogs, portals,
intranet site and e - commerce also.
 
some of them are :
 

BlogEngine.NET

blogengine

URL: http://dotnetblogengine.net
Source Code: Grab the source code here
Project Description
BlogEngine.NET may be the simplest and most light weight ASP.NET blog at the moment,
but still full featured. Here are some of the features:

- Multi-author support
- Pingbacks and trackbacks
- Event based for plug-in writers
- Theming directly in master pages and user controls
- Gravatar and coComments implemented
- Live preview on commenting
- Comment moderation
- BlogML import/export
- Extension model
- Code syntax highlighting
- Mono support
- Full editing and creation of pages that are not posts
- Extended search capabilities
- Tag cloud
- Self updating blogroll
- Runs entirely on XML or SQL Server. Your choice.

YetAnotherForum

yetanotherjpg
YAF is a Open Source discussion forum or bulletin board system for web sites running
ASP.NET. The latest production version runs on ASP.NET v2.0 with a Microsoft SQL
Server backend.

URL: http://www.yetanotherforum.net/
Source Code: Grab the source code here

DotNetNuke

dotnetnuke
DotNetNuke is an open source web application framework ideal for creating, deploying and
managing interactive web, intranet, and extranet sites securely.

URL: http://www.dotnetnuke.com
Source Code: Grab the source code here

MojoPortal

mojoportal

URL: http://www.mojoportal.com/
Source Code: Grab the source code here

nopCommerce

nopcommerce

Running on C# nopCommerce is a fully customizable shopping cart. It's stable and highly
usable. nopCommerce is a open source e-commerce solution that is ASP.NET 3.5 based
with a MS SQL 2005 backend database.

URL: http://www.nopcommerce.com/
Source Code: Grab the source code here

 


 

Tuesday, July 26, 2011

progress Bar in swing

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class SplashScreen extends JWindow
{
private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;
private static Timer timer1;
public SplashScreen()
{

setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new javax.swing.border.EtchedBorder());
panel.setBackground(Color.red);
panel.setBounds(10,10,348,150);
panel.setLayout(null);

add(panel);
JLabel label = new JLabel("Hello World!");
label.setFont(new Font("Verdana",Font.BOLD,14));
label.setBounds(85,25,280,30);
panel.add(label);

progressBar.setMaximum(50);
progressBar.setBounds(55, 180, 250, 15);

add(progressBar);
loadProgressBar();
setSize(375,300);
setLocationRelativeTo(null);
setVisible(true);
}
public void loadProgressBar()
{
ActionListener al = new ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
count++;
progressBar.setValue(count);
if (count == 51){
timer1.stop();
execute.setVisible(false);

//load the rest of your application

}
}};
timer1 = new Timer(300, al);
timer1.start();
}

public static void main (String args[]){
execute = new SplashScreen();
}
}

Wednesday, July 20, 2011

Importance of Enumerations

Enumerations are simple value types that allow developers to choose from a list of constants.

Behind the scenes, an enumeration is just an ordinary integral number where every value has

a special meaning as a constant. However, because you refer to enumeration values using their

names, you don’t need to worry about forgetting a hard-coded number, or using an invalid

value.

To define an enumeration, you use the block structure shown here:

public enum FavoriteColors

{

Red,

Blue,

Yellow,

White

}

This example creates an enumeration named FavoriteColors with three possible values:

Red, Blue, and Yellow.

Once you’ve defined an enumeration, you can assign and manipulate enumeration values

like any other variable. When you assign a value to an enumeration, you use one of the predefined

named constants. Here’s how it works:

// You create an enumeration like an ordinary variable.

FavoriteColors buttonColor;

// You assign and inspect enumerations using a property-like syntax.

buttonColor = FavoriteColors.Red;

In some cases, you need to combine more than one value from an enumeration at once.

To allow this, you need to decorate your enumeration with the Flags attribute, as shown here:

[Flags]

public enum AccessRights

{

Read = 0x01,

Write = 0x02,

Shared = 0x04,

}

This allows code like this, which combines values using a bitwise or operator:

AccessRights rights = AccessRights.Read | AccessRights.Write | AccessRights.Shared;
You can test to see if a single value is present using bitwise arithmetic with the & operator

to filter out what you’re interested in:

if ((rights & AccessRights.Write) == AccessRights.Write)

{

// Write is one of the values.

}

Enumerations are particularly important in user-interface programming, which often has

specific constants and other information you need to use but shouldn’t hard-code. For example,

when you set the color, alignment, or border style of a button, you use a value from the appropriate

enumeration.