Labels

Wednesday, August 31, 2011

The breakpoint will not currently be hit. No symbols have been loaded for this document.

  1. While debugging in Visual Studio, click on Debug > Windows > Modules. The IDE will dock a Modules window, showing all the modules that have been loaded for your project.
  2. Look for your project's DLL, and check the Symbol Status for it.
  3. If it says Symbols Loaded, then you're golden. If it says something like Cannot find or open the PDB file, right-click on your module, select Load Symbols, and browse to the path of your PDB.
I've found that it's sometimes necessary to
  • stop the debugger
  • close the IDE
  • close the hosting application
  • nuke the obj and bin folders
  • restart the IDE
  • rebuild the project
  • go through the Modules window again
Once you browse to the location of your PDB file, the Symbol Status should change to Symbols Loaded, and you should now be able to set and catch a breakpoint at your line in code.

Wednesday, August 24, 2011

Load Text File into SQL Server

SQL Bulk insert

ADO.NET SQLBulkCopy

In ADO .NET, SqlBulkCopy is the object that helps you to perform a bulk copy.  You can use a DataReader or DataTable as source data store (you can load your data from SQL database, Access database, XML or ... into these objects easily) and copy them to a destination table in database.

Copying only updated rows, Mapping Columns
Using a DataReader - most efficient way to bulk copy data between SQL Servers using .NET


SQL Server Integration Services

Running SSIS package programmatically


Wednesday, August 17, 2011

dynamic sql - From Clause Table name Variable

Create procedure s_ProcTable
@TableName varchar(128)
as
declare @sql varchar(4000)
 select @sql = 'select rows = count(*) from [' + @TableName + ']'
 exec (@sql)
go

Now executing this will give the result.
Note the [] around the name in case it contains invalid characters.
You may also have to deal with the owner.

Using EXECUTE 'tsql_string' with a variableThe following example shows how EXECUTE handles dynamically built strings that contain variables. This example creates the tables_cursor cursor to hold a list of all user-defined tables in the AdventureWorks2008R2 database, and then uses that list to rebuild all indexes on the tables.

USE AdventureWorks2008R2;
GO
DECLARE tables_cursor CURSOR
   FOR
   SELECT s.name, t.name
   FROM sys.objects AS t
   JOIN sys.schemas AS s ON s.schema_id = t.schema_id
   WHERE t.type = 'U';
OPEN tables_cursor;
DECLARE @schemaname sysname;
DECLARE @tablename sysname;
FETCH NEXT FROM tables_cursor INTO @schemaname, @tablename;
WHILE (@@FETCH_STATUS <> -1)
BEGIN;
   EXECUTE ('ALTER INDEX ALL ON ' + @schemaname + '.' + @tablename + ' REBUILD;');
   FETCH NEXT FROM tables_cursor INTO @schemaname, @tablename;
END;
PRINT 'The indexes on all tables have been rebuilt.';
CLOSE tables_cursor;
DEALLOCATE tables_cursor;
GO

Tuesday, August 9, 2011

Installation Package Tools

Visual Studio Installer
Will be discontinued after 2012, introduced new Installshield

The WiX distribution includes Votive, a Visual Studio add-in that allows creating and building WiX setup projects using the Visual Studio IDE. Votive supports syntax highlighting and IntelliSense for .WXS source files and adds a WiX setup project type to Visual Studio.

Installation cause VS IDE extremely slow when edit the file.

Thursday, August 4, 2011

Unit Test Best Practise

Test Driven Development (TDD) process is a robust way of designing software components (“units”) interactively so that their behaviour is specified through unit tests.

Goal Strongest technique
Finding bugs (things that don’t work as you want them to) Manual testing (sometimes also automated integration tests)
Detecting regressions (things that used to work but have unexpectedly stopped working) Automated integration tests (sometimes also manual testing, though time-consuming)
Designing software components robustly Unit testing (within the TDD process)

when you’re refactoring, i.e., restructuring a unit’s code but without meaning to change its behaviour. In this case, unit tests can often tell you if the unit’s behaviour has changed.

Unit Test in Visual Studio 2010
Walkthrough: Creating and Running Unit Tests
Walkthrough: Run Tests and View Code Coverage
Walkthrough: Using the Command-line Test Utility

Walkthrough: Create And Run Unit Tests As Part of a Team Build

MSTest Issues in 2008:
1. MSTest has limited support for parametrized tests and it is very cumbersome and constraining.
2. MSTest is stuck with the current release of VS and one has to wait till the next full release of VS to get any new features for unit testing whereas with NUnit and the like you can get new features and bugs fixes quickly.
3.limitations on how third party tools like TeamCity can work with MSTest

Schedule Task Table Design

CREATE TABLE [dbo].[Schedule](
 [ScheduleID] [int] NOT NULL,
 [ScheduleTaskID] [int] NULL,
 [ScheduleFrequency] [varchar](20) NOT NULL, /*Once, Daily, Weekly, Biweekly, Monthly, Yearly*/
 [ScheduleStatus] [varchar](50) NULL,                 /*A-Enabled, X-Disabled*/
 [ScheduleStart] [smalldatetime] NULL,               /*Full vaule used by Once and Biweekly, Time part only used by Others*/
 [ScheduleEnd] [smalldatetime] NULL,                /**/
 [MonthWeekDay] [smallint] NULL,                    /*This will override Start and End column*/
 [LastModifyUser] [varchar](50) NULL,
 [LastModifyDate] [smalldatetime] NULL, 
CONSTRAINT [PK_Schedule] PRIMARY KEY CLUSTERED
( [ScheduleID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[ScheduleException](
 [ScheduleID] [int] NOT NULL,
 [ExceptionDateStart] [smalldatetime] NOT NULL,
 [ExceptionDateEnd] [smalldatetime] NOT NULL
) ON [PRIMARY]


CREATE TABLE [dbo].[ScheduleExecution](
 [ScheduleID] [int] NOT NULL,
 [ScheduleTaskID] [varchar](50) NOT NULL,
 [ExecuteStart] [datetime] NOT NULL,
 [ExecuteEnd] [datetime] NULL,
 [ExecuteStatus] [varchar](50) NOT NULL,
 [RequestUser] [varchar](50) NULL,
 [RequestTime] [datetime] NULL
) ON [PRIMARY]


1). Read "Developing Time-Oriented Database Applications in SQL" by Richard Snodgrass (http://www.cs.arizona.edu/people/rts/tdbbook.pdf). This is a free PDF book which is perhaps the best resource on developing temporal databases.

2). Review some existing data models that relate to scheduling, like:
http://www.databaseanswers.org/data_models/services_job_scheduling/index.htm
http://www.databaseanswers.org/data_models/hairdressers/index.htm
Look at this resources to see if it provides any ideas.
http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=FirstAvailableTimeslot&referringTitle=Home

Tibor's article on working with date, time, and datetime values is excellent.
http://www.karaszi.com/SQLServer/info_datetime.asp

Eralper's discussion on Calendar tables is worth reading:
http://www.kodyaz.com/articles/sql-server-dates-table-using-tsql-cte-calendar-table.aspx

Another discussion of using a Calendar table:
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html


CREATE TABLE [dbo].[ScheduleException](
 [ScheduleID] [int] NOT NULL,
 [ExceptionDateStart] [smalldatetime] NOT NULL,
 [ExceptionDateEnd] [smalldatetime] NOT NULL
) ON [PRIMARY]

Wednesday, August 3, 2011

Copy database from sql 2008 to sql express

You can NOT use  Copy Database Wizard when destination server is SQL Server Express Edition.

Use backup and restore instead but keep in mind database size must be less than 4 GB.

Try copying  with DB scripts, Database >> Tasks >> Generate Scripts >>
Refer this link for additional info
http://blog.sqlauthority.com/2009/07/29/sql-server-2008-copy-database-with-data-generate-t-sql-for-inserting-data-from-one-table-to-another-table/

Try using DATABASE publishing wizard to generate scripts with schema and data.
http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en