Archive for the ‘VS2005-SQL’ Category

Remote Debugging (Managed Code)

December 19, 2007
I just revisted this issue.  (See my previous bloggs on this).
 
Created simple project in VS2005 called fred
 
Create share called share on target called sata (Security setting open as possible.  fw turned off!)
Copied the Remote debugger dir from VS2005 (Program files, under Common IDE) to the share
 
When I ran msvmon on target I got a prompt to change local security setting as follows:
Network Acess: Sharing and security model for local accounts , to , Classic Local User authenticate as themselves
Did this
 
In the project properties in VS2005 I set:
The build dir to \\sata\share on Compile tab
On Debug tab:
"Start External Progarm"  \\sata\share\fred.exe
"Working dir" \\sata\share
-[Tick] "Use Remote Machine" administrator@sata
 
PS Was logged as administrator (with same password and in in same Workgroup) on both machines.
 
I was getting  failure to connect.
So enabled everyone in the debugging permissions vis MSMON
 
Connection registered on target when I tried to rerun (Debug) but failed:
Message on dev machine that was similar to when I tried to MSVMON.
 
THEN THE PENNY DROPPED!
 
I had to do the same local security setting on the dev machine!
 
And it worked
 
.. Wala
 

More on tracing

December 4, 2007
I created a range of code snippets (C#) to embedd tracing based upon the f.NET ramestack.
This makes it a lot easer to insert tracing.
eg  t-r-a-tab-tab  to insert a trace at a certain line.
Certain snippets handle the class declaration  t-r-d-e-c-tab-tab
etc
 
Note that to expand code snippets you type its key and tab twice as above.
 
I wrote my snippets in XML as per the VS help.
Then I placed them in my VS folder under My Documents, Code Snippets sub folder-C#-MySnippets
eg C:\Documents and Settings\David\My Documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets
 
A sample snippet
The filename doesn’t matter except that it has to have the file extension .snippet (even though its XML)
=================================
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 <CodeSnippet Format="1.0.0">
  <Header>
   <Title>
    TraceExit
   </Title>
   <Shortcut>Trexit</Shortcut>
  </Header>
  <Snippet>
   <Code Language="CSharp">
    <![CDATA[dbg.traceExit( new System.Diagnostics.StackTrace(true));]]>
   </Code>
  </Snippet>
 </CodeSnippet>
</CodeSnippets>
 
The CDATA can be spread over several lines.
 
I’ll refine this and publish it soomewhere.
 
PS: I ended just using MessageBoxes in the embedded copde though!
 
 

Debug: Trace Capability added

December 1, 2007

I’ve added some formal tracing capability to the class.

To call the method trace (eg dbg logit class instance) : 

dbg.trace( new StackTrace(new StackFrame(true)));

//Don’t call this, used by trace method
private void traceLog(String message1, String message2, String message3, String message4, String message5, String message6)
        {
            if (!db) return;
            try
            {
                if (_db) tw.WriteLine("TRACE: " + (_traceIndex++).ToString() +
                    message1 + " " + message2 +
                     message3 + " " + message4 +
                    message5 + " " + message6);
             }
            catch { }
        }

 

        /// <summary>
        /// Call: 
        ///  trace( new StackTrace(new StackFrame(true)));
        /// Explanation:
        /// Place the call as above, in the line that you want to trace at.
        /// Will log filename, linename and current method
        /// Requires:
        /// using System.Diagnostics;
        /// </summary>
        /// <param name="st">Tackframe object instance</param>
        public void trace(StackTrace st)
        {
            // Display file, line and method nameinformation, if available.
            //trace(new StackTrace(new StackFrame(true)));
            StackFrame sf = st.GetFrame(0);
            traceLog(
                " File: ", sf.GetFileName().ToString(),
                " Line Number: ", sf.GetFileLineNumber().ToString(),
                " Method: ", sf.GetMethod().ToString()
            );

        }

Debug Class

November 30, 2007
Still have some trouble with remote debugging on XPe.
 
I decided to formalise the writeline technique with a debug class called Debugg.
This borrows from the debug macros/API in Windows CE where messages are conditional and local.
 
Each class instantiates the class in its constructor
The first class opens the file to write to.
You place a Debugg method at the start and end of each function that you want to debug.
There are log messages that you then use.
 
Its posted below:
=================

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using System.Collections;

 

namespace Debugg

{

    public class logit

    {

        /// <summary>

        /// Constructors

        /// Place in paraent class Initialiser/contructor at end.

        /// </summary>

        public logit()

        {

            _logit( "VOID");

        }

        public logit(String ClassFile)

                    {

            _logit( ClassFile);

        }

        private void _logit(String ClassFile)

        {            

            if (!db) return;

 

            _ClassFile = ClassFile;

            if (_classCount++ == 0) firstClass = true;

            else firstClass = false;

 

            if (tw == null)

            {

                try

                {

                    if (_logFile != "") tw = new StreamWriter(_logFile);

                }

                catch { }

 

            }

            if (tw != null)  tw.WriteLine((_index++).ToString() + _ClassFile + " Entered");

        }

 

        /// <summary>

        /// Properties/Fields

        /// </summary>

 

        private string _ClassFile = "";

        private int _classCount =0;

        private Boolean firstClass = false;

 

        private static Boolean  _db = true;

        public static Boolean db

        {

            get { return _db; }

            set {

                _db =                     value;

            }

        }

 

        private  Boolean _mydb = true;

        public  Boolean mydb

        {

            get { return _mydb; }

            set

            {

                _mydb = value;

            }

        }

 

        private static int _index=1;

        public static int index

        {

            get { return _index; }

            set { _index = value ; }

        }

 

        private static TextWriter tw=null;

        private static String _logFile="C:\\temp\\loggfile.txt";

        public static String logFile

        {

            get { return _logFile; }

            set {

                if (tw != null) tw.Close();

                _logFile = value;

            }

        }

 

        /// <summary>

        /// Logging methods

        /// </summary>

        /// <param name="num"></param>

        /// <param name="message"></param>

        public void logg(int num,String message)

        {

            if (!db) return;

            try

            {

                if (_db) tw.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + num.ToString() + " " + message);

            }

            catch { }

            }

        public void logg(String message)

        {

            if (!db) return;

 

            try

            {

                if (_db) tw.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + "     " + " " + message);

            }

            catch{}

        }

        public void logg()

        {

            if (!db) return;

 

            try

            {

                if (_db) tw.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + "     " + " " + "Closing");

            }

            catch { }

            }

 

        /// <summary> 
        /// Function enter/exit logging 
        /// Place as first loc in function and as last loc in function 
        /// </summary> 
        private string _currentFunctionName =""; 
        private  Stack myStack = new Stack(); 
        public void enterr(String FunctionName) 
        { 
            if (!db) return; 
              try 
            { 
                myStack.Push(_currentFunctionName); 
                _currentFunctionName = FunctionName; 
                if (_db) 
                { 
                    tw.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + "     " + " " + "Entered"); 
                    System.Diagnostics.Debug.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + "     " + " " + "Entered");                 } 
             } 
            catch{}{}; 
        }

        public void exitt( ) 
        {  
            if (!db) return; 

              try{ 
                _currentFunctionName = myStack.Pop().ToString(); 
                if (_db) { 
                    tw.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + "     " + " " + "Exited"); 
                     System.Diagnostics.Debug.WriteLine((_index++).ToString() + _ClassFile + " " + _currentFunctionName + " " + "     " + " " + "Exited"); 
                }

            } 
            catch{}{}; 
        }

 

        /// <summary> 
        /// Place in parent class Dispaose method: 
        /// </summary> 
        public void done() 
        { 
            if (!db) return; 

            logg(); 

            { 
                try 
                { 

                    if (firstClass) 
                    { 
                        tw.Flush(); 
                        tw.Close(); 
                    } 
                } 
                catch   {   } 
            } 
        }   
    }
}

 

=================
Enjoy!

VS 2005 Remote Debugging: Updated

August 13, 2007

30/10/07
======
I revisted this issue yesterday.
I was trying to debug from Vista to XP (VS managed code).
This wouldn’t work.  See my postings on MS Forums:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2341292&SiteID=1&mode=1
When I reversed things it worked!  (dev on Vista, target on XP).
I have added some snapshots of the Project.Debug panels here.

 

Aug 07
===========

I spent some time today and yesterday tring to get Remote debugging in Visual Studio 2005 (Managed Code) going.  I don’t think that the documentation is that good.
I got itgoing today, as a VB.NET console app running on an XP Embedded system remotely with breakpoint and stepping etc.

I took a snapshot of the project-debug settings.:

 

Project.Debug for 30/11


Previous Project

Vista VS 2005 SP1 Update released.

March 8, 2007

Doc says:

Installation requirements

You must have a licensed copy of one or more supported Visual Studio 2005 products installed.

You must have Visual Studio 2005 Service Pack 1 (SP1) installed.

=============

Some discussion at:

http://www.microsoft.com/presspass/features/2007/mar07/03-06VisualStudio.mspx

=============

One thing that is recommended with VS2005 in Vista is to run as admin.

I see nothing in this release that addresses taht issue.
Will post a comment if anything comes up; or feel free to post a comment if you know anything about that.

Cheers

=============

PS I installed it without any issues

SQL 2005 Express Running .SQL Scripts (HOW TO)

April 11, 2006
The default install for VS2005 Professional includes SQL 2005 Express.
The express edition is just the engine, no management tools such as Query Analyser (to run .sql scripts etc against).
 
The problem then is how to import a new database that is in a .SQLscript?
I resolved that from VS by: 
(a) Creating a new SP in Master db
     In that SP is the create db command  (Usually the first part of the .SQL script)
    Run it
(b) Create a new SP in the new db to populate the db  (The rest of the script)
    Run it
 
Need to remove Go and USE  lines from script
 
Wala!