/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu

Tuesday, March 27, 2012

Public Vs Shared in VB.NET OOPS Concept

public vs shared

public vs. shared -------------------------------------------------------------------------------- Public and Shared aren't comparable like protected and private and public and friend are. Those are access modifiers - they modify who has the right to access them. Public simply means that any code can access the member (function/property/field). Shared which is more like a flag (something either is shared or isn't), indicates that the member (function/property/field) doesn't behave/belong to a specific instance of the class. So your own definitions are pretty accurate, I simply want to make it clear that public and shared aren't comparable. Something can be public shared, private shared, friend shared, protected shared or simply public, private, friend or protected (then there's protected friend, but we'll ignore that for now). private shared means that only the class itself can access the field, a frequent use of a private shared field is for use with singletons: public class MyClass private shared MyClass instance = nothing public shared function GetInstance() as MyClass if instance is nothing then instance = new MyClass() end if return instance() end function private sub new() end sub ... end class from the above code you can see that MyClass can never be created directly since the constructor is private (outside code can't call it). Outside code also can't access the instance field because it too is private. Outside code can however access GetInstance because it's public. GetInstance checks to see if the private field "instance" is nothing (it can access a private field because it's all the same class), if it is, it creates the instance (again, it can access the private constructor) and returns the instance (there is a possible race condition, but that's besides the point). What's neat about the above example is that GetInstance is marked shared. IF it wasn't, no one would ever be able to call it because the constructor is private and thus an instance can't be created. Without an instance, a non-shared member can't be accessed.
Solution

Public and Shared aren't comparable like protected and private and public and friend are. Those are access modifiers - they modify who has the right to access them. Public simply means that any code can access the member (function/property/field). Shared which is more like a flag (something either is shared or isn't), indicates that the member (function/property/field) doesn't behave/belong to a specific instance of the class. So your own definitions are pretty accurate, I simply want to make it clear that public and shared aren't comparable. Something can be public shared, private shared, friend shared, protected shared or simply public, private, friend or protected (then there's protected friend, but we'll ignore that for now). private shared means that only the class itself can access the field, a frequent use of a private shared field is for use with singletons:[CODE] public class MyClass private shared MyClass instance = nothing public shared function GetInstance() as MyClass if instance is nothing then instance = new MyClass() end if return instance() end function private sub new() end sub ... end class[/CODE] from the above code you can see that MyClass can never be created directly since the constructor is private (outside code can't call it). Outside code also can't access the instance field because it too is private. Outside code can however access GetInstance because it's public. GetInstance checks to see if the private field "instance" is nothing (it can access a private field because it's all the same class), if it is, it creates the instance (again, it can access the private constructor) and returns the instance (there is a possible race condition, but that's besides the point). What's neat about the above example is that GetInstance is marked shared. IF it wasn't, no one would ever be able to call it because the constructor is private and thus an instance can't be created. Without an instance, a non-shared member can't be accessed. You might find Paul Vick's great VB.Net book useful:

http://books.google.com/books?id=ejzRTF2TL6UC&prev=http://print.google.com/print%3Fq%3Dpaul%2Bvick&pg=1&sig=ZxfWU68bu9eUj6Q910vyvVa9Gwg&hl=en
Read More »

Thursday, February 23, 2012

Javascript Calender Example

Read More »

Thursday, January 19, 2012

SQL SERVER: The server principal is not able to access the database

SQL Databases not showing up . . .

If you accessing MSSQL 2005 with MSSQL 2008 management studio, you might getting error of The server principal is not able to access the database when log into the database server.

 

To fix it,
1. Connect to SQL Server Management Studio.
2. Connect to the SQL server.
3. Click “View” and then select on the “Object Explorer Details”. (This step could be done from shortcut F7)
4. Double click on the “Databases” folder.
5. Right click on the column header “Policy Health State”.
6. Untick the option “Collation”.
7. Refresh it and you have done.
Read More »

Wednesday, January 11, 2012

ASP.NET - javascript popup message box

//javascript popup message box


public void ShowPop(string Message)

{

ClientScript.RegisterStartupScript(this.GetType(), "OhCrap", String.Format("alert('{0}');", Message.Replace("'", "\'")), true);

}

Read More »

Sunday, January 8, 2012

How to configure SQL Server 2005 to allow remote connections

To enable remote connections on the instance of SQL Server 2005 and to turn on the SQL Server Browser service, use the SQL Server 2005 Surface Area Configuration tool. The Surface Area Configuration tool is installed when you install SQL Server 2005.

Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer

Editionmust enable remote connections for each instance of SQL Server 2005 that you want to connect to from a remote computer. To do this, follow these steps:
  1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
  2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
  3. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.

    Note Click OK when you receive the following message:
    Changes to Connection Settings will not take effect until you restart the Database Engine service.
  4. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.
Read More »

My Blog List