Rename SQL Server 2005 Database and Datafile

Some of this SQL Commands don’t work in SQL Server 2000.


use master;

ALTER DATABASE Cheque_Req MODIFY FILE (NAME =Cheque_Req_Data, FILENAME = 'C:\ABC.MDF')
ALTER DATABASE Cheque_Req MODIFY FILE (NAME =Cheque_Req_Log, FILENAME = 'C:\ABC.LDF')


ALTER DATABASE Cheque_Req MODIFY FILE (NAME =Cheque_Req_Data, NEWNAME = 'cib')
ALTER DATABASE Cheque_Req MODIFY FILE (NAME =Cheque_Req_Log, NEWNAME = 'cib_log')

alter database Cheque_Req set offline;
-- copy existing data and log file and placed in new desired location
alter database Cheque_Req set online;

ALTER DATABASE Cheque_Req Modify Name = cibDB; 

Thanks
A Rahim Khan

SQL to find out and disable child tables referencing parent table in SQL Server

You can use this query to find out child tables referencing parent Table.

 
--replace 't_User'with your table name
--query to find out which table have references
select
  so.name 'foreign key name',
  OBJECT_NAME(parent_obj) 'table',
  OBJECT_NAME(sf.fkeyid) 'referencing table',
  sc1.name 'referencing column',
  OBJECT_NAME(sf.rkeyid) 'referenced table', 
  sc2.name 'referenced column'
from sysobjects so
inner join sysforeignkeys sf on so.id = sf.constid
inner join syscolumns sc1 on sf.fkeyid = sc1.id and sf.fkey = sc1.colid
inner join syscolumns sc2 on sf.rkeyid = sc2.id and sf.fkey = sc2.colid
where so.xtype in ('F','PK')
and OBJECT_NAME(sf.rkeyid) = 't_User'

Continue reading

Javascript Confirmation with ASP.NET Validations

It was difficult for me to find out how to use submit confirmation while using ASP.NET validations in Web Form. This following one is the Java Script Function to be used.


   function ConfirmSubmit() {
    
        Page_ClientValidate();

        if (Page_IsValid) {

            return confirm('Do you want add this User?');

        }
        
        return Page_IsValid;
    }


Use it this way with your Submit Button.


onclientclick="return ConfirmSubmit();"

Thanks
A Rahim Khan

StateServer Session Mode with Class (Object) ASP.NET

First of all, ASP.NET State Service is to be on to use StateServer Session.
Place this piece of code in your Web.Config File.


sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false" timeout="120"

Now you can start using StateServer Session, rest of the steps are same all kind of Sessions.

However, if you are storing any Class’s Object in StateServer Session, this particular class requires Serialization. Have a look at this User Class, it’s object can be stored in StateServer Session. Continue reading

Get Web User IP Address for Local Network Web Application

This is going to work only for Local network Web Application, it will return proxy’s IP if anyone using Proxy to connect your Web Application.


string userIpAddress = Request.UserHostAddress.ToString();

Thanks
A Rahim Khan

Set Value to ASP.NET Password Mode TextBox

You can’t directly set value for Password Mode TextBox like Normal Single/Multiline TextBox. You got to do it like


userPasswordTextBox.Attributes["value"] = "PASSWORD";
retypePasswordTextBox.Attributes["value"] = "RETYPE PASSWORD";

Thanks
A Rahim Khan

Number Only TextBox C# Windows Application

Put this code snippet your TextBox KeyPress Event, you will have your Number Only TextBox Working.


private void numberOnlyTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
 //allow digits only
 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
 {
   e.Handled = true;
 }

 // allow one decimal point
 if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
 {
  e.Handled = true;
 }
}


Thanks
A Rahim Khan

Follow

Get every new post delivered to your Inbox.

Join 74 other followers