Data Dictionary Queries for SQL Server & Oracle


For SQL Server

–Finding all details of Primary Key constraint
select * from sysobjects
where xtype=’PK’

–Finding all details of Foreign Key constraint
select * from sysobjects
where xtype=’F’

–Finding all User-Defined objects (tables, etc)
select * from sysobjects
where xtype=’U’

–Finding all System objects
select * from sysobjects
where xtype=’S’

–Finding all user names
select * from sysusers

–Finding Column Names of Particular Table
–Select Pubs Database
select c.name from sysobjects o, syscolumns c
where o.id = c.id ando.name = ‘publishers’

For ORACLE
select * from sys.dba_objects
where owner = ‘scott’and object_type=’TABLE’
SELECT owner, object_name, object_type FROM sys.dba_objects
where object_type=’SEQUENCE’ and owner=’scott’;

Advertisements

Implementing a Singleton Class in .NET


http://msdn.microsoft.com/en-us/library/ms998426.aspx
http://msdn.microsoft.com/en-us/library/ms998558.aspx

using System;

public class Singleton
{
private static Singleton instance;

private Singleton() {}

public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}

Benefits


Instance control. Singleton prevents other objects from instantiating their own copies of the Singleton object, ensuring that all objects access the single instance.

Flexibility. Because the class controls the instantiation process, the class has the flexibility to change the instantiation process.

Liabilities


Overhead. Although the amount is minuscule, there is some overhead involved in checking whether an instance of the class already exists every time an object requests a reference. This problem can be overcome by using static initialization as described in Implementing Singleton in C#.

Possible development confusion. When using a singleton object (especially one defined in a class library), developers must remember that they cannot use the new keyword to instantiate the object. Because application developers may not have access to the library source code, they may be surprised to find that they cannot instantiate this class directly.

Object lifetime. Singleton does not address the issue of deleting the single object. In languages that provide memory management (for example, languages based on the .NET Framework), only the Singleton class could cause the instance to be deallocated because it holds a private reference to the instance. In languages, such as C++, other classes could delete the object instance, but doing so would lead to a dangling reference inside the Singleton class.

How to implement a Custom Error Mechanism for ASP .NET pages


Adding this code in Global.asax gives ur application the ability to redirect the user to the specified page in case an unhandled exception occurs,

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
string username;
username = “UserID: TempUser”;

Exception exp = Server.GetLastError();
string to = ConfigurationSettings.AppSettings[“ToAddress”];
string from = ConfigurationSettings.AppSettings[“FromAddress”];
string subject = “Error in application”;

string message = exp.Message + “\r\n” + exp.ToString();
MessageMailSend.SendMessage(to, from, subject, message);

Response.Redirect(“ErrorPage.aspx”);

}

How to send an Email from ASP .NET


WEB.CONFIG SETTINGS

<appsettings>

<add key=”ToAddress” value=”myemail@test.com”>
<add key=”FromAddress” value=”error@test.com”>
<add key=”host” value=”HOST”>
</appsettings>
</span>


…….
<system.net>
<mailSettings>
<smtp deliveryMethod=”Network” from=”test@test.com”>
<network host=”localhost” port=”25″ defaultCredentials=”true”/>
</smtp>
</mailSettings>
</system.net>


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

///
/// Summary description for MessageMailSend
///
public class MessageMailSend
{
public MessageMailSend()
{
//
// TODO: Add constructor logic here
//
}
public static bool SendMessage(string to,string from,string subject,string message)
{
try
{
MailMessage msg = new MailMessage();
msg.To = to;
msg.Subject = subject;
msg.From = from;
msg.BodyFormat = MailFormat.Text;
msg.Body = message;
SmtpMail.Send(msg);
return true;
}
catch (Exception exp)
{
}
return false;
}
}