First you need to create a user on your desktop and the remote machine with the same username and password on both machines.
Make sure msvsmon.exe is installed on the remote computer. It should be in your Visual studio 2008 directory.
on the remote computer do a runas /user:debuguser c:\fullpath\msvsmon.exe
where debuguser is the user you created above
You should see a window popup saying "3/31/2009 12:22:56 PM Msvsmon started a new server named 'debuguser@TSIK2552100'. Waiting for new connections."
now on your desktop do a runas /user:debuguser "c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
where debuguser is again the user you created above
the load your project and go to attach to process, enter debuguser@remotemachinename in the Qualifier box and you may need to select the show processes from all users check box. select your process and you should be able to debug.
Wednesday, October 7, 2009
Monday, September 28, 2009
Enable Sql Server Authentication Mode Over Network
Check the followings:
1. Right click the root node on Object Explorer, in Server Properties window->Security->Server authentication: SQL Server and Windows Authentication mode
2. Create a new user for login.
3. Right click the user on Object Explorer, in Login Properties window:
3.1 User Mapping: Check the desired database to access
3.2 Status->Permission to connect to database engine: Grant; Login: Enabled
4. Sql Server Configuration Manager -> Enable TCP/IP and Named Pipes
5. REMEMBER TO RESTART THE MSSQLSERVER SERVICE.
1. Right click the root node on Object Explorer, in Server Properties window->Security->Server authentication: SQL Server and Windows Authentication mode
2. Create a new user for login.
3. Right click the user on Object Explorer, in Login Properties window:
3.1 User Mapping: Check the desired database to access
3.2 Status->Permission to connect to database engine: Grant; Login: Enabled
4. Sql Server Configuration Manager -> Enable TCP/IP and Named Pipes
5. REMEMBER TO RESTART THE MSSQLSERVER SERVICE.
Thursday, September 17, 2009
Object.GetHashCode, Object.Equals, operator==, and related
After some research, I summarize some points below as guidelines.
1.Object.Equals method and operator== are supposed to be used interchangeably. (It applies to all the .net classes) Therefore, when implementing a new class, it's a good idea to always implement both of them.
Equals() is usually used (implemented) for value equality and Operator== is used for reference equality by default. When a type is an immutable type (e.g. String), overloading Operator== to compare value equality makes sense.
Guidelines for Overloading Equals() and Operator==
http://msdn.microsoft.com/en-us/library/ms173147%28VS.80%29.aspx
Override equals on overloading operator equals
http://msdn.microsoft.com/en-us/library/ms182357%28VS.80%29.aspx
When should I use == and when should I use Equals
http://blogs.msdn.com/csharpfaq/archive/2004/03/29/102224.aspx
2. It is important to override GetHashCode when overriding Equals method. Although failure to do so will not always break your code, things can go wrong if the class is used as a key in a dictionary etc. In that situation, if the hash-code for two items does not match, they may never be considered equal (Equals will never be called). To write the GetHashCode, we need to make sure that: if two objects are equal, then they must return the same value for GetHashCode. On the other hand, we do NOT have to make sure two different objects always return different values for GetHashCode.
Why is it important to override GetHashCode when Equals method is overriden in C#
http://stackoverflow.com/questions/371328/why-is-it-important-to-override-gethashcode-when-equals-method-is-overriden-in-c
3. A good implementation of GetHashCode that can be used in many situations:
http://stackoverflow.com/questions/263400#263416
4. Implementing IEquatable Properly
http://www.codeproject.com/KB/dotnet/IEquatable.aspx
1.
Equals() is usually used (implemented) for value equality and Operator== is used for reference equality by default. When a type is an immutable type (e.g. String), overloading Operator== to compare value equality makes sense.
Guidelines for Overloading Equals() and Operator==
http://msdn.microsoft.com/en-us/library/ms173147%28VS.80%29.aspx
Override equals on overloading operator equals
http://msdn.microsoft.com/en-us/library/ms182357%28VS.80%29.aspx
When should I use == and when should I use Equals
http://blogs.msdn.com/csharpfaq/archive/2004/03/29/102224.aspx
2. It is important to override GetHashCode when overriding Equals method. Although failure to do so will not always break your code, things can go wrong if the class is used as a key in a dictionary etc. In that situation, if the hash-code for two items does not match, they may never be considered equal (Equals will never be called). To write the GetHashCode, we need to make sure that: if two objects are equal, then they must return the same value for GetHashCode. On the other hand, we do NOT have to make sure two different objects always return different values for GetHashCode.
Why is it important to override GetHashCode when Equals method is overriden in C#
http://stackoverflow.com/questions/371328/why-is-it-important-to-override-gethashcode-when-equals-method-is-overriden-in-c
3. A good implementation of GetHashCode that can be used in many situations:
public int GetHashCode()
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + field1.GetHashCode();
hash = hash * 23 + field2.GetHashCode();
hash = hash * 23 + field3.GetHashCode();
return hash;
}
What is the best algorithm for an overridden System.Object.GetHashCodehttp://stackoverflow.com/questions/263400#263416
4. Implementing IEquatable Properly
http://www.codeproject.com/KB/dotnet/IEquatable.aspx
Tuesday, August 25, 2009
Sql Server Script to Restore a Database
use master
alter database DBName
set single_user with rollback immediate
restore database DBName
from disk = 'C:\DBBackup.bak'
-- use the following to overwrite log in case the log file was not backed up
with replace
alter database DBName
set single_user with rollback immediate
restore database DBName
from disk = 'C:\DBBackup.bak'
-- use the following to overwrite log in case the log file was not backed up
with replace
Tuesday, August 18, 2009
SQL Commands - Disable Constraints
The following commands are from this URL
http://gchandra.wordpress.com/2008/02/18/sql-server-clean-your-database-records-and-reset-identity-columns-the-shortest-path/
--Disable Constraints & Triggers
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
--Perform delete operation on all table for cleanup
exec sp_MSforeachtable 'DELETE ?'
--Enable Constraints & Triggers again
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
--Reset Identity on tables with identity column
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
I found the commands are very useful. For example, I once got the foreign key constraint error when trying to import data into my database. I executed the first two commands to disable constraints and triggers first, then imported the data, the errors were gone. After importing data, I then executed the last three commands to re-enable and reset stuff.
http://gchandra.wordpress.com/2008/02/18/sql-server-clean-your-database-records-and-reset-identity-columns-the-shortest-path/
--Disable Constraints & Triggers
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
--Perform delete operation on all table for cleanup
exec sp_MSforeachtable 'DELETE ?'
--Enable Constraints & Triggers again
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
--Reset Identity on tables with identity column
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
I found the commands are very useful. For example, I once got the foreign key constraint error when trying to import data into my database. I executed the first two commands to disable constraints and triggers first, then imported the data, the errors were gone. After importing data, I then executed the last three commands to re-enable and reset stuff.
Wednesday, July 22, 2009
WaitCallback method has to be static
The following is a demo for using WaitCallback delegate. Note that the method ThreadProc has to be static.
using namespace System;
using namespace System::Threading;
ref class Example
{
public:
// This thread procedure performs the task.
static void ThreadProc( Object^ stateInfo )
{
// No state object was passed to QueueUserWorkItem, so
// stateInfo is 0.
Console::WriteLine( "Hello from the thread pool." );
}
};
int main()
{
// Queue the task.
ThreadPool::QueueUserWorkItem( gcnew WaitCallback( Example::ThreadProc ) );
Console::WriteLine( "Main thread does some work, then sleeps." );
// If you comment out the Sleep, the main thread exits before
// the thread pool task runs. The thread pool uses background
// threads, which do not keep the application running. (This
// is a simple example of a race condition.)
Thread::Sleep( 1000 );
Console::WriteLine( "Main thread exits." );
return 0;
}
If it's not static, we'll get the following error:
error C3867: 'Example::ThreadProc': function call missing argument list; use '&Example::ThreadProc' to create a pointer to member
error C3350: 'System::Threading::WaitCallback' : a delegate constructor expects 2 argument(s)
Why??
using namespace System;
using namespace System::Threading;
ref class Example
{
public:
// This thread procedure performs the task.
static void ThreadProc( Object^ stateInfo )
{
// No state object was passed to QueueUserWorkItem, so
// stateInfo is 0.
Console::WriteLine( "Hello from the thread pool." );
}
};
int main()
{
// Queue the task.
ThreadPool::QueueUserWorkItem( gcnew WaitCallback( Example::ThreadProc ) );
Console::WriteLine( "Main thread does some work, then sleeps." );
// If you comment out the Sleep, the main thread exits before
// the thread pool task runs. The thread pool uses background
// threads, which do not keep the application running. (This
// is a simple example of a race condition.)
Thread::Sleep( 1000 );
Console::WriteLine( "Main thread exits." );
return 0;
}
If it's not static, we'll get the following error:
error C3867: 'Example::ThreadProc': function call missing argument list; use '&Example::ThreadProc' to create a pointer to member
error C3350: 'System::Threading::WaitCallback' : a delegate constructor expects 2 argument(s)
Why??
Wednesday, June 24, 2009
Calling javascript from code behind
Previously, we know how to easily call server side method from javascript. The opposite is also simple enough.
Just use the RegisterClientScriptBlock method of ClientScriptManager (in case of full postback) or ScirptManager (in case of patial postback). Following is an example:
confirmInPageNav can be any javascript function
Just use the RegisterClientScriptBlock method of ClientScriptManager (in case of full postback) or ScirptManager (in case of patial postback). Following is an example:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "confirmInPageNav", "<script>confirmInPageNav()</script>", false);
confirmInPageNav can be any javascript function
Subscribe to:
Posts (Atom)