SQL server data base restore script
Friday, July 03, 2009 7:29 AM

this is a quick trick that i googled from bits and pieces in a caffe when my laptop didn’t have a Management studio installed

i found a way to execute sql scripts to my instance of sql express

well to restore you need to have the logical names of files in the database backup to know that

just type

RESTORE FILELISTONLY
FROM DISK = ‘<path to your backup file>’

this will display all the logical file’s in the backup in the result sets

you’ll need the logical file names for the coming script (the actual restore)

 

RESTORE DATABASE <DataBaseName>
FROM DISK = ‘<path to your backup file>’
WITH MOVE ‘<Data file logical Name>’ TO '<path to resotre your datafile>',
MOVE '<log file logical name >' TO '<path to restore your log file>'

by amir.magdy | with no comments
Filed under: ,
How To Design A Good API by Joshua Bloch Google
Wednesday, June 24, 2009 1:55 PM
http://www.youtube.com/v/aAb7hSCtvGw&hl=en&fs=1&
Database or Object Size in SQL server [sp_spaceused]
Monday, June 01, 2009 1:02 AM

Space used by the objects in the database is a tricky subject, this can be very useful when planning your database maintenance plan

a system stored procedure as you probably had figured is called sp_spaceused gets you the needed information

that procedure can be used in multiple ways

use Northwind
exec sp_spaceused

when this is executed against your database this data appears

image

it shows two result sets the first one which is a Whole Database statistics

  1. DatabasName
  2. database size in MBs and
  3. Space in the database that has not been reserved for database objects in MB also (this is space that is reserved by the Database and has not been allocated to any database objects yet)

the second group shows

  1. data that has been reserved for all objects (this includes pages that has no data and fragmented pages)
  2. Actual Data size inside the tables pages
  3. index size
  4. unused space

 

sometimes you might get negative values, that is normal as sometimes the usage information is not updated in that case you can do this

 

USE Northwind
GO
EXEC sp_spaceused @updateusage = N'TRUE';

 

it will update usage information and then return the same values as the first sample

now. you can also get statistics that are specific to an object

you can do this simply by

 

USE Northwind;
GO
EXEC sp_spaceused N'Employees';
GO
image

in addition to reserved space and data and index size you also get the rows count

by amir.magdy | with no comments
Filed under: ,
Fiddler 2 to monitor localhost ie7
Wednesday, May 27, 2009 6:46 AM

IE7 and .net framework are programmed never to request data localhost

Just change the wording Localhost to your machine Name.

this is a better explanation http://www.fiddler2.com/fiddler/help/hookup.asp#Q-LocalTraffic

by amir.magdy | with no comments
Filed under: ,
Change Web Service test page [wsdlHelpGenerator]
Tuesday, May 26, 2009 4:24 AM

the default web service page is a page that reveals a lot of the internal information of the application, this is something that you want to hide.

Warning this does not really secure your web service. may be you should read something like this

<configuration>
   <system.web>
      <webServices>
         <wsdlHelpGenerator href="yourEmptyPage.aspx"/>
      </webServices>
   </system.web>
</configuration>

 

just make sure you add a page to your site’s root folder and name it yourEmptyPage.aspx this way whenever someone navigates to your web services URL that page is going to render

by amir.magdy | with no comments
Filed under: , ,
Windows Debugging tools Quick tutorial [WinDbg]
Sunday, May 17, 2009 11:42 PM

last week end we have faced memory leaks, we had no idea what was the cause of the problem. we were directed by microsoft to use the debugging tools.

this is a quickest possible startup tutorial for that tool.

[Warning] using this tool affects the performance of your applications dramatically please make sure you don’t run it on a production server unless there’s no other way.

    1. download link
      you are looking for “Install Debugging Tools for Windows xx-bit Version”
      you’ll be redirected to the download page u’ll need to look for the “current version”
    2. install the tool
      this is probably the only straight forward step in this tutorial
    3. Copy SOS.dll *
      u need to copy this dll from your framework folder
      usually %windir%\Microsoft.NET\Framework\v2.0.50727
      to your windbg folder
      usually %ProgramFiles%\Debugging Tools for Windows (x86)
    4. Open the WindDbgTool
      image
    5. Symbol data
      to view internals of assemblies you need symbol data the easiest way is to have it downloaded automatically. you can do that by
      image
      and typing in

      srv*c:\symbols\public*http://msdl.microsoft.com/download/symbols
       
      image

      just make sure you have internet connection so this can be downloaded.
    6. Get a Memory Dump of your application
      well this is another 3 step tutorial
      .
    7. Open the Dump
      ”File”->”Open Crash dump” (if prompted you don’t have to save.)
      select the file and wait for the application to be ready
      image 

      this is actually an option i like as attaching to the process causes the application to be extremely slow and you can always ask your client to create a dump and FTP it to you
    8. you need to load “SOS”
      in the previous window the text box in the bottom is where you’ll type in commands.
      the first you need is to load SOS

      so type in
      .load SOS
      AND NOTHING HAPPENS, yes there’s no confirmation that the thing was loaded.

    9. your first Command
      now there’s a whole bunch of commands that can be executed from the SOS you can list all these commands by typing in
      !sos.help
    10. need help
      and now you can explore the memory dump of your application on your own just consider the hints in the next box.

      //!SOS.help <methodName>
      
      !SOS.help DumpDomain
      
      !SOS.DumpDomain



This is just a quick help to get you started. if you need to understand what’s behind this please refer http://blogs.msdn.com/tess/  thank you Tess for the time

by amir.magdy | 1 comment(s)
Filed under: , ,
Fastest way for Creating a memory Dump of your application [DebugDiag]
Sunday, May 17, 2009 11:37 PM
  1. First you need to download the tool here is the link
  2. now just install the tool and run it
  3. then ignore the wizard and go to the third tab in the application UI
    image

right click your process and select create a full dump, the dump is going to be created

now if you need to configure where these dumps are created go to tools –> options and configure the dumps folder.

by amir.magdy | 2 comment(s)
Filed under: , ,
JSON Serialization in AJAX.net both Client side and Server side
Tuesday, April 14, 2009 6:34 AM

JSON objects representations are small and lightweight compared to XML they are now the core of AJAX.net services serialization. in AJAX.net they work out of the box

you can serilaize/deserialize  your objects to JSON using this snippet of server side code

using System.Web.Script.Serialization;
JavaScriptSerializer jss = new JavaScriptSerializer();
//Serialize
jss.Serialize(object);
//Deserialize
yourCustomType result = jss.Deserialize<yourCustomType>(yourJSONString);

 

and on the client side you can do the same as long as you have a script manager in your page

// Serialization
var jsonString= Sys.Serialization.JavaScriptSerializer.serialize(JSObject);
//deserialization 
var JSObject= Sys.Serialization.JavaScriptSerializer.deserialize(jsonString);
AL.exe error when compiling in Visual Studio 2008
Tuesday, March 10, 2009 4:48 AM

when i first Installed Visual Studio 2008 Team system i was trying to compile the application i just migrated from visual studio 2005

and i got the error

 

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1950,9): error MSB3011: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\AL.exe" was not found. Either 1) Install the .NET Framework SDK, which will install AL.exe. Or 2) Pass the correct location of AL.exe into the "ToolPath" parameter of the AL task.

Solution 1 :

the fix is simple you need to download the AL.exe as part of the SDK you can find it here 

Solution 2 :

or you can download a zip file that i have copied from another computer which has the SDK i have included the files here 41Kb

copy that to your SDK folder as you have installed visual studio it’s already created so copy the two files from the zip to this path

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

and then you have to update the registry of its location

so

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows]
"CurrentIA64Folder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v5.0\\"
"CurrentIA64Version"="v5.0"
"CurrentInstallFolder"="C:\\Program Files\\\\Microsoft SDKs\\Windows\\v6.0A\\"

 

copy the previous code snippet to a new text file called “newfile.reg” double click it

you may have to restart visual studio for it to work

visual studio 2008 Team System setup a problem encountered while loading the setup components canceling setup
Tuesday, March 10, 2009 4:27 AM

i wanted to install an additional feature of Visual studio 2008 but when i started the setup process or tried to uninstall the application i got this error

“Setup a problem encountered while loading the setup components. Canceling setup.”

the Fix

i went to check for fixes under that application uninstalled it and the the setup worked fine

by amir.magdy | with no comments
Filed under: , ,
Dynamically create domain users
Tuesday, February 10, 2009 2:14 AM

My Team was planning a Stress test scenario to be run on our stress lab, the application we were planning to test needed windows authentication to function.

The plan was to create a set of users with predefined passwords and add them to the domain so the application can be tested correctly. We used VBscript that creates the users from a database table this is the code used.

Dim aConnectionString
aConnectionString = "Provider=SQLOLEDB;Data " _
& "Source=srvr;Database=UrDataBaseName;" _
& "UID=usr; PWD=psw;"
Dim conn,R,SQL,RecsAffected
'connect to database
Set conn=CreateObject("ADODB.Connection")
conn.Mode =3
conn.ConnectionString = aConnectionString
conn.Open
Dim strCommand
Dim Users,comm,UsersCommandText
Set comm=CreateObject("ADODB.Command")
comm.ActiveConnection =conn
UsersCommandText= "SELECT [UserName] from [Users]"
comm.commandtext= UsersCommandText
Set Users = Comm.Execute
' this is like assigning 
' a reader with the result set
' only here it's called a recordset
If Not (Users.Eof and Users.Bof ) Then
Users.MoveNext
While Not Users.EOF
  
  Dim strUser
  Dim objRootLDAP, objContainer, objNewUser
  strUser = Users("UserName")
  
  ' Bind to Active Directory, Users container.
  Set objRootLDAP = GetObject("LDAP://YourDomainName")
  Dim defaultContext  
  defaultContext = "DC=YourDomainName,DC=com" 
  Set objContainer = GetObject("LDAP://cn=Users," & defaultContext  ) 
  ' now this is the container that you are going to use
  
  ' now you can Build the actual User.
  Set objNewUser = objContainer.Create("User", "cn=" & strUser)
  objNewUser.Put "sAMAccountName", strUser
  objNewUser.AccountDisabled=False  
  objNewUser.setpassword "123"
        objNewUser.SetInfo 
  
  Set objNewUser = objContainer.GetObject("User", "cn=" & strUser)
  objNewUser.AccountDisabled=False
  objNewUser.SetInfo   
  
  MsgBox (Users("UserName")) 
  ' seriously don't do this if u have a few hundred users
  Users.MoveNext
Wend
End If
conn.Close
by amir.magdy | 1 comment(s)
Filed under: ,
Dynamically Resize an IFrame According to its contents
Tuesday, November 25, 2008 4:30 AM

problem with iframe is that you can't always predict the size of the content and eventually you'd end up with a scrollbar or even less convenient: a hidden part of the Iframe content

this is a straight forward, easy way to make sure that the IFrame is properly resized according to the contents of the page loaded inside the Iframe.

 

this will rely on the browser itself measuring the content width and height

this can be done by using the document.body.scrollHeight and document.body.scrollWidth properties which work the same way in all browsers IE and firefox

 

just to make sure that these properties work properly we'll set the initial width and height of the Iframe to 1 pixel so we can have a scroll bar to measure. if it's larger than that the scroll bars won't measure the whole width and height of the document and if it's 0 the reported scroll Area will be also Zero

 

body

one more issue to target is the margins. because we're using a subsection of the document which has the scroll Area Body does not include margins in that case we need to neutralize the effect of margins on the page. this can be done easily by setting the margins of the page to zero

 

resulting code would be in the Container page :

<iframe id="frameName" 
src="frame.html" width="1" height="1" 
frameborder="0" marginheight="0" marginwidth="0" 
scrolling="no"></iframe>

 

note that i have added the scrolling="no" attribute to make sure that there's no scrollbars displayed and i have also neutralized the border size by frameborder="0"

 

inner page would be like this in the End of the <body> i have added this simple javascrip

 

function doFrame(){            
    parent.document.getElementById("frameName").width= document.body.scrollWidth;
    parent.document.getElementById("frameName").height= document.body.scrollHeight;
}
doFrame();

 

note how i reference the frame by its Id.

by amir.magdy | 4 comment(s)
Filed under: ,
Google Browser Chrome
Monday, September 01, 2008 2:12 PM

Google have disclosed that they're going to release a new browser called Chrome. this is big news

here is the link,these are comics that google released to explain about the browser.

by amir.magdy | with no comments
Filed under:
Most Used Javascript Date functions
Thursday, August 21, 2008 12:16 PM

 

var OneDay = 1000*60*60*24;
 
function subtractDates (firstDate,secondDate){                    
    return Math.ceil((new Date(firstDate).getTime()
        -new Date(secondDate).getTime())/(OneDay));
}
 
 
function addDays (dateToAdd,amountInDays){
    return  new Date(dateToAdd.valueOf() + this.OneDay * amountInDays);
}
 
function daysInMonth (year,month){                       
    var m = [31,28,31,30,31,30,31,31,30,31,30,31];
    if (month != 2)
        return m[month - 1];
    if (year%4 != 0)
        return m[1];
    if (year%100 == 0 && year%400 != 0)
        return m[1]
    return m[1] + 1;
}
 
 
 
function isDate(dateStr){
    var ok;
    try{
    var d = Date.parse(dateStr);
        return true;
    }catch(x){
        return false;
    }
}
by amir.magdy | 1 comment(s)
Filed under:
Android 0.9
Monday, August 18, 2008 11:17 PM

Android 0.9 has just launched it has major UI updates

Download it here http://code.google.com/android/download_list.html

by amir.magdy | with no comments
Filed under:
More Posts Next page »