Sunday, December 13, 2009

VB.Net Draw String Center of Point location

Private Sub DrawStringCenterOfPoint(ByRef gr As Graphics, _
ByVal txt As String, ByVal txtfont As Font, _
ByVal txtcolor As Brush, ByVal location As PointF)

' Mark the center for debugging
Dim x as Single = location.X
Dim y as Single = location.Y
gr.DrawLine(New Pen(Color.Red, 2), x - 10, y, x + 10, y)

' Make a StringFormat object that centers
Dim sf As New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center

' Draw the text.
Dim StringSize As New SizeF
StringSize = gr.MeasureString(txt, txtfont)

gr.DrawString(txt, txtfont, txtcolor, x, y, sf)
sf.Dispose()

End Sub

VB.Net Find Center of a Polygon

Private Function CenterOfPolygon(ByRef _pointf() As PointF) As PointF
CenterOfPolygon = New Point(0, 0)

Dim total_points As Integer = _pointf.Length
Dim x_total As Single = 0, y_total As Single = 0
For Each _point As PointF In _pointf
x_total = x_total + _point.X
y_total = y_total + _point.Y
Next

CenterOfPolygon.X = x_total / total_points
CenterOfPolygon.Y = y_total / total_points

End Function

Tuesday, June 30, 2009

Application Architecture Guide 2.0

The purpose of the Application Architecture Guide 2.0 is to improve your effectiveness when building applications on the Microsoft platform. The primary audience for this guide is solution architects and development leads.
The guide provides design-level guidance for the architecture and design of applications built on the Microsoft .NET platform. It focuses on the most common types of applications and on partitioning application functionality into layers, components, and services, and also walks through their key design characteristics.
The guidance is task-based and presented in parts that correspond to major architecture and design focus points. It is designed to be used as a reference resource, or it can be read from beginning to end. The guide is divided into the following four parts:

• Part I, “Fundamentals,” provides you with the fundamentals you will need in order to understand architecture design techniques and strategies.
• Part II, “Design,” provides overarching design guidelines and practices that can be applied to any application type or application layer, including guidelines on how to design a communications solution and plan for services.
• Part III, “Layers,” provides architecture and design approaches, as well as practices for each layer, including the presentation, business, service, and data access layers.
• Part IV, “Archetypes,” provides patterns and design frames for each application archetype; including service applications, Web applications, rich client applications, rich Internet applications (RIA), and mobile applications.


Application Types:Architecture Styles:Architecture Frame:
- Mobile
- RIA
- Rich Client
- Services
- Web Applications
- Client Server
- Component Based
- Layered Architecture
- Message Bus
- MVC Architecture
- N-Tier
- Object Oriented
- SOA
- Caching
- Communication
- Concurrency and Transactions
- Configuration Management
- Coupling and Cohesion
- Data Access
- Exception Management
- Layering
- Logging and Instrumentation
- State Management
- Structure
- Validation
- Workflow


Reference:
http://www.codeplex.com/AppArchGuide

Saturday, June 27, 2009

Microsoft SQL Server 2008 - Maximum Capacity Specifications

Maximum Capacity Specifications for SQL Server 2008

The following tables specify the maximum sizes and numbers of various objects defined in SQL Server components.

Database Engine Objects

The following table specifies the maximum sizes and numbers of various objects defined in SQL Server databases or referenced in Transact-SQL statements.

SQL Server Database Engine object

Maximum sizes/numbers SQL Server (32-bit)

Maximum sizes/numbers SQL Server (64-bit)

Batch size1

65,536 * Network Packet Size

65,536 * Network Packet Size

Bytes per short string column

8,000

8,000

Bytes per GROUP BY, ORDER BY

8,060

8,060

Bytes per index key2

900

900

Bytes per foreign key

900

900

Bytes per primary key

900

900

Bytes per row8

8,060

8,060

Bytes in source text of a stored procedure

Lesser of batch size or 250 MB

Lesser of batch size or 250 MB

Bytes per varchar(max), varbinary(max), xml, text, or image column

2^31-1

2^31-1

Characters per ntext or nvarchar(max) column

2^30-1

2^30-1

Clustered indexes per table

1

1

Columns in GROUP BY, ORDER BY

Limited only by number of bytes

Limited only by number of bytes

Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement

10

10

Columns per index key7

16

16

Columns per foreign key

16

16

Columns per primary key

16

16

Columns per nonwide table

1,024

1,024

Columns per wide table

30,000

30,000

Columns per SELECT statement

4,096

4,096

Columns per INSERT statement

4096

4096

Connections per client

Maximum value of configured connections

Maximum value of configured connections

Database size

524,272 terabytes

524,272 terabytes

Databases per instance of SQL Server

32,767

32,767

Filegroups per database

32,767

32,767

Files per database

32,767

32,767

File size (data)

16 terabytes

16 terabytes

File size (log)

2 terabytes

2 terabytes

Foreign key table references per table4

253

253

Identifier length (in characters)

128

128

Instances per computer

50 instances on a stand-alone server for all SQL Server editions except for Workgroup. Workgroup supports a maximum of 16 instances per computer.

SQL Server supports 25 instances on a failover cluster.

50 instances on a stand-alone server.

25 instances on a failover cluster.

Length of a string containing SQL statements (batch size)1

65,536 * Network packet size

65,536 * Network packet size

Locks per connection

Maximum locks per server

Maximum locks per server

Locks per instance of SQL Server5

Up to 2,147,483,647

Limited only by memory

Nested stored procedure levels6

32

32

Nested subqueries

32

32

Nested trigger levels

32

32

Nonclustered indexes per table

999

999

Number of distinct expressions in the GROUP BY clause when any of the following are present: CUBE, ROLLUP, GROUPING SETS, WITH CUBE, WITH ROLLUP

32

32

Number of grouping sets generated by operators in the GROUP BY clause

4,096

4,096

Parameters per stored procedure

2,100

2,100

Parameters per user-defined function

2,100

2,100

REFERENCES per table

253

253

Rows per table

Limited by available storage

Limited by available storage

Tables per database3

Limited by number of objects in a database

Limited by number of objects in a database

Partitions per partitioned table or index

1,000

1,000

Statistics on non-indexed columns

30,000

30,000

Tables per SELECT statement

Limited only by available resources

Limited only by available resources

Triggers per table3

Limited by number of objects in a database

Limited by number of objects in a database

Columns per UPDATE statement (Wide Tables)

4096

4096

User connections

32,767

32,767

XML indexes

249

249

1 Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 KB, and is controlled by the network packet size configuration option.

2 The maximum number of bytes in any index key cannot exceed 900 in SQL Server. You can define a key using variable-length columns whose maximum sizes add up to more than 900, provided no row is ever inserted with more than 900 bytes of data in those columns. In SQL Server, you can include nonkey columns in a nonclustered index to avoid the maximum index key size of 900 bytes.

3 Database objects include objects such as tables, views, stored procedures, user-defined functions, triggers, rules, defaults, and constraints. The sum of the number of all objects in a database cannot exceed 2,147,483,647.

4 Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional FOREIGN KEY constraints may be expensive for the query optimizer to process.

5 This value is for static lock allocation. Dynamic locks are limited only by memory.

6 If a stored procedure accesses more than 8 databases, or more than 2 databases in interleaving, you will receive an error.

7 If the table contains one or more XML indexes, the clustering key of the user table is limited to 15 columns because the XML column is added to the clustering key of the primary XML index. In SQL Server, you can include nonkey columns in a nonclustered index to avoid the limitation of a maximum of 16 key columns. For more information, see Index with Included Columns.

8 SQL Server supports row-overflow storage which enables variable length columns to be pushed off-row. Only a 24-byte root is stored in the main record for variable length columns pushed out of row; because of this, the effective row limit is higher than in previous releases of SQL Server. For more information, see the "Row-Overflow Data Exceeding 8 KB" topic in SQL Server Books Online.

Saturday, June 20, 2009

Microsoft .Net - Value Types and Reference Types

A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.

Value Types

Value types include the following:

· All numeric data types

· Boolean, Char, and Date

· All structures, even if their members are reference types

· Enumerations, since their underlying type is always SByte, Short, Integer, Long, Byte, UShort, UInteger, or ULong

Reference Types

Reference types include the following:

· String

· All arrays, even if their elements are value types

· Class types, such as Form

· Delegates

Elements That Are Not Types

The following programming elements do not qualify as types, because you cannot specify any of them as a data type for a declared element:

· Namespaces

· Modules

· Events

· Properties and procedures

· Variables, constants, and fields

Working with the Object Data Type

You can assign either a reference type or a value type to a variable of the ObjectObject variable always holds a pointer to the data, never the data itself. However, if you assign a value type to an Object variable, it behaves as if it holds its own data. For more information, see data type. An Object Data Type.

You can find out whether an Object variable is acting as a reference type or a value type by passing it to the IsReference method on the Information class in the Microsoft.VisualBasic namespace. Microsoft.VisualBasic.Information.IsReference(System.Object) returns TrueObject variable represents a reference type. if the content of the

Monday, June 15, 2009

Microsoft. Net - Replace BitMap Color

Private Function ReplaceBitMapColor(ByVal originalBMP As Bitmap, _
ByVal oldColor As Color, _
ByVal newColor As Color) As Bitmap
Dim image As New Bitmap(originalBMP)
Dim graphics As Graphics = Graphics.FromImage(image)
Dim map As ColorMap() = New ColorMap() {New ColorMap}
map(0).OldColor = oldColor
map(0).NewColor = newColor

Dim imageAttr As New ImageAttributes
imageAttr.SetRemapTable(map)

Dim destRect As New Rectangle(0, 0, image.Width, image.Height)
graphics.DrawImage(image, destRect, 0, 0, _
image.Width, image.Height, _
GraphicsUnit.Pixel, imageAttr)

Return image

End Function

Wednesday, May 27, 2009

Microsoft SQL Server 2005 - Maximum Capacity Specifications

Maximum Capacity Specifications for SQL Server 2005

The following tables specify the maximum sizes and numbers of various objects defined in Microsoft SQL Server 2005 components.

Database Engine Objects

The following table specifies the maximum sizes and numbers of various objects defined in SQL Server 2005 databases or referenced in Transact-SQL statements. The table does not include SQL Server Windows CE Edition.

SQL Server 2005 Database Engine object

Maximum sizes/numbers SQL Server 2005 (32-bit)

Maximum sizes/numbers SQL Server 2005 (64-bit)

Batch size1

65,536 * Network Packet Size

65,536 * Network Packet Size

Bytes per short string column

8,000

8,000

Bytes per GROUP BY, ORDER BY

8,060

8,060

Bytes per index key2

900

900

Bytes per foreign key

900

900

Bytes per primary key

900

900

Bytes per row8

8,060

8,060

Bytes per varchar(max), varbinary(max), xml, text, or image column

2^31-1

2^31-1

Characters per ntext or nvarchar(max) column

2^30-1

2^30-1

Clustered indexes per table

1

1

Columns in GROUP BY, ORDER BY

Limited only by number of bytes

Limited only by number of bytes

Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement

10

10

Columns per index key7

16

16

Columns per foreign key

16

16

Columns per primary key

16

16

Columns per base table

1,024

1,024

Columns per SELECT statement

4,096

4,096

Columns per INSERT statement

1,024

1,024

Connections per client

Maximum value of configured connections

Maximum value of configured connections

Database size

524,258 terabytes

524,258 terabytes

Databases per instance of SQL Server

32,767

32,767

Filegroups per database

32,767

32,767

Files per database

32,767

32,767

File size (data)

16 terabytes

16 terabytes

File size (log)

2 terabytes

2 terabytes

Foreign key table references per table4

253

253

Identifier length (in characters)

128

128

Instances per computer

50 instances on a stand-alone server for all SQL Server 2005 editions except for Workgroup Edition. Workgroup Edition supports a maximum of 16 instances.

SQL Server 2005 supports 25 instances on a failover cluster.

50 instances on a stand-alone server.

25 instances on a failover cluster.

Length of a string containing SQL statements (batch size)1

65,536 * Network packet size

65,536 * Network packet size

Locks per connection

Maximum locks per server

Maximum locks per server

Locks per instance of SQL Server5

Up to 2,147,483,647

Limited only by memory

Nested stored procedure levels6

32

32

Nested subqueries

32

32

Nested trigger levels

32

32

Nonclustered indexes per table

249

249

Parameters per stored procedure

2,100

2,100

Parameters per user-defined function

2,100

2,100

REFERENCES per table

253

253

Rows per table

Limited by available storage

Limited by available storage

Tables per database3

Limited by number of objects in a database

Limited by number of objects in a database

Partitions per partitioned table or index

1,000

1,000

Statistics on non-indexed columns

2,000

2,000

Tables per SELECT statement

256

256

Triggers per table3

Limited by number of objects in a database

Limited by number of objects in a database

UNIQUE indexes or constraints per table

249 nonclustered and 1 clustered

249 nonclustered and 1 clustered

User connections

32,767

32,767

XML indexes

249

249

1 Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 kilobytes (KB), and is controlled by the network packet size configuration option.

2 The maximum number of bytes in any index key cannot exceed 900 in SQL Server 2005. You can define a key using variable-length columns whose maximum sizes add up to more than 900, provided no row is ever inserted with more than 900 bytes of data in those columns. In SQL Server 2005, you can include nonkey columns in a nonclustered index to avoid the maximum index key size of 900 bytes. For more information, see Index with Included Columns.

3 Database objects include objects such as tables, views, stored procedures, user-defined functions, triggers, rules, defaults, and constraints. The sum of the number of all objects in a database cannot exceed 2,147,483,647.

4 Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional foreign key constraints may be expensive for the query optimizer to process.

5 This value is for static lock allocation. Dynamic locks are limited only by memory.

6 If a stored procedure accesses more than 8 databases, or more than 2 databases in interleaving, you will receive an error.

7 If the table contains one or more XML indexes, the clustering key of the user table is limited to 15 columns because the XML column is added to the clustering key of the primary XML index. In SQL Server 2005, you can include nonkey columns in a nonclustered index to avoid the limitation of a maximum of 16 key columns. For more information, see Index with Included Columns.

8 SQL Server 2005 supports row-overflow storage which enables variable length columns to be pushed off-row. Only a 24-byte root is stored in the main record for variable length columns pushed out of row; because of this, the effective row limit is higher than in previous releases of SQL Server. For more information, see the "Row-Overflow Data Exceeding 8 KB" topic in SQL Server 2005 Books Online.

Thursday, May 21, 2009

Regular Expressions

Phone or Fax 999-999-9999
"\d{3}\-\d{3}\-\d{4}"

Phone or Fax (999) 999-9999
"\(\d{3}\) \d{3}\-\d{4}"

Simple Email
(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})

Email blah@blah.com
"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$"

Email blah._blah@blah.com
"^(([\w-]+\.)+[\w-]+|([a-zA-Z0-9]{1}|[\w-]{2,}))+@([-0-9a-zA-Z]+[._])+[a-zA-Z]{2,6}$"

Number 965
"\d\"

Wednesday, May 6, 2009

Why Vista Failed?

Windows 7 is through beta, it is now release candidate, soon we are going to have a brand new operating system from Microsoft. I have been some what loyal to Microsoft Windows, when i worked on Windows 98 for the first time it was like Wow! I would say Windows 98 really changed the way people think about a personal computer. When Windows Me came in, i decided to stick with Windows 98, reason was i did not find any reason to switch as Windows 98 was doing everything i wanted at that time. When Windows XP, i still kept with Windows 98 until Windows XP Service pack 1 came in.

Now i am using Windows XP Service pack 3, i installed a dual boot with Windows Vista a number of times, but was unable to convince myself to switch. As i have been so used too with Windows XP and i really like it now.
Windows Vista Service pack 1 is a real improvement, but compatibility issue of Windows Vista with its predecessors is one of the reasons most of the users are not switching. Still i have kept Vista on a Virtual machine.

Reasons behind failure of Vista i think:
1. Strong security model, which keeps showing annoying dialog windows, and it is so frequent that users get used to just click OK without bothering for it, because they want to complete a task quickly

2. Hardware requirements, so Windows XP users will have to buy a new hardware if they want to have Windows Aero

3. Performance promises not met, seem to be slow as compare to XP

4. Windows Vista not showing backward computability is biggest reason among all

5. Most of the IT industry have applications developed that run nicely on Windows XP, but same application tends to crash on Vista without a clue

6. Software Vendors are also getting problem in making their programs work on Vista, for this they have to maintain a Virtual machine all the time to test their code on Vista.

7. For gamers that like their old games as well, get a set back when they see the older games are not working well on Vista

I hope Microsoft gets around and fixes them in the up coming Windows 7, i am hopping for the best, otherwise i will keep myself with Windows XP, and let Vista run on a Virtual machine.

Sunday, May 3, 2009

Using Missing Index Information to Write CREATE INDEX Statements

SELECT 'CREATE NONCLUSTERED INDEX NewNameHere ON ' + sys.schemas.name
+ '.' + sys.objects.name + ' ( ' + mid.equality_columns + CASE WHEN mid.inequality_columns IS NULL
THEN '' ELSE CASE WHEN mid.equality_columns IS NULL
THEN '' ELSE ',' END + mid.inequality_columns END + ' ) ' +
CASE WHEN mid.included_columns IS NULL
THEN '' ELSE 'INCLUDE (' + mid.included_columns + ')' END + ';' AS CreateIndexStatement,
mid.equality_columns, mid.inequality_columns, mid.included_columns
FROM sys.dm_db_missing_index_group_stats AS migs
INNER JOIN sys.dm_db_missing_index_groups AS mig
ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details AS mid
ON mig.index_handle = mid.index_handle
INNER JOIN sys.objects WITH (nolock)
ON mid.object_id = sys.objects.object_id
INNER JOIN sys.schemas
ON sys.objects.schema_id = sys.schemas.schema_id
WHERE (migs.group_handle IN ( SELECT TOP 100 PERCENT group_handle
FROM sys.dm_db_missing_index_group_stats WITH (nolock)
ORDER BY (avg_total_user_cost * avg_user_impact) * (user_seeks + user_scans) DESC
AND sys.objects.type = 'U'



MSDN : Using Missing Index Information to Write CREATE INDEX Statements


Brian Knight's blog on the Missing Index DMV




Reference: http://msdn.microsoft.com/en-us/library/ms345405(SQL.90).aspx

Friday, May 1, 2009

Text Area Maximum Length

/*Text Area Maximum Length

<textarea cols="40" rows="3" id="" wrap="physical"

onKeyUp="return textCounter(this.form.other,this.form.remLen_1,100);"

onKeyDown="return textCounter(this.form.other,this.form.remLen_1,100);" name="other"></textarea>

<input type="text" name="remLen_1" value="100">

*/

function textCounter(field, countfield, maxlimit) {

var textlength = field.value.length;

if (textlength > maxlimit) {

field.value = field.value.substring(0, maxlimit);

} else {

countfield.value = maxlimit - textlength;

}

}

Wednesday, April 29, 2009

Enabled/Disable HTML Elements


function EnableDisabled(elName)
{
var el = document.getElementById(elName);
if(el){
try {el.disabled = el.disabled ? false : true;}
catch(ex){}

if (el.childNodes && el.childNodes.length > 0)
{
for (var x = 0; x < el.childNodes.length; x++)
{
EnableDisabled(el.childNodes[x]);
}
}
}
}

Monday, April 27, 2009

VB.Net - Export DataTable to CSV

Public Sub ExportDataTableToCSV(ByRef dtSource As DataTable, _
ByVal filename As String)

Dim context As HttpContext = HttpContext.Current
context.Response.Clear()
For Each column As DataColumn In dtSource.Columns
context.Response.Write(column.ColumnName + ",")
Next
context.Response.Write(Environment.NewLine)

For Each row As DataRow In dtSource.Rows
For i As Integer = 0 To dtSource.Columns.Count - 1
context.Response.Write(row(i).ToString().Replace(",", String.Empty) + ",")
Next
context.Response.Write(Environment.NewLine)
Next

context.Response.ContentType = "text/csv"
context.Response.AppendHeader("Content-Disposition", _
"attachment; filename=" + filename + ".csv")
context.Response.End()

End Sub

Saturday, April 25, 2009

VB.Net - Get Week Number of a date

Public Function GetWeekNumber(ByVal inDate As DateTime) As Integer
Const JAN As Integer = 1
Const DEC As Integer = 12
Const LASTDAYOFDEC As Integer = 31
Const FIRSTDAYOFJAN As Integer = 1
Const THURSDAY As Integer = 4
Dim ThursdayFlag As Boolean = False

' Get the day number since the beginning of the year
Dim DayOfYear As Integer = inDate.DayOfYear

' Get the numeric weekday of the first day of the
' year (using sunday as FirstDay)
Dim StartWeekDayOfYear As Integer = _
DirectCast(New DateTime(inDate.Year, JAN, FIRSTDAYOFJAN).DayOfWeek, Integer)
Dim EndWeekDayOfYear As Integer = _
DirectCast(New DateTime(inDate.Year, DEC, LASTDAYOFDEC).DayOfWeek, Integer)

' Compensate for the fact that we are using monday
' as the first day of the week
If StartWeekDayOfYear = 0 Then
StartWeekDayOfYear = 7
End If
If EndWeekDayOfYear = 0 Then
EndWeekDayOfYear = 7
End If

' Calculate the number of days in the first and last week
Dim DaysInFirstWeek As Integer = 8 - StartWeekDayOfYear
Dim DaysInLastWeek As Integer = 8 - EndWeekDayOfYear

' If the year either starts or ends on a thursday it will have a 53rd week
If StartWeekDayOfYear = THURSDAY OrElse EndWeekDayOfYear = THURSDAY Then
ThursdayFlag = True
End If

' We begin by calculating the number of FULL weeks
' between the start of the year and
' our date. The number is rounded up, so the smallest possible value is 0.
Dim FullWeeks As Integer = _
CType(Math.Ceiling((DayOfYear - DaysInFirstWeek) / 7), Integer)

Dim WeekNumber As Integer = FullWeeks

' If the first week of the year has at least four days,
' then the actual week number for our date
' can be incremented by one.
If DaysInFirstWeek >= THURSDAY Then
WeekNumber = WeekNumber + 1
End If

' If week number is larger than week 52
' (and the year doesn't either start or end on a thursday)
' then the correct week number is 1.
If WeekNumber > 52 AndAlso Not ThursdayFlag Then
WeekNumber = 1
End If

' If week number is still 0,
' it means that we are trying to evaluate the week number for a
' week that belongs in the previous year
' (since that week has 3 days or less in our date's year).
' We therefore make a recursive call using the last day of the previous year.
If WeekNumber = 0 Then
WeekNumber = GetWeekNumber( _
New DateTime(inDate.Year - 1, DEC, LASTDAYOFDEC))
End If

Return WeekNumber
End Function

Monday, April 20, 2009

VB.Net - Get Weeks In a Year


Public Function GetWeeksInYear(ByVal dayofsunday As DateTime) As Integer

Dim dayofthursday As DateTime = dayofsunday.AddDays(-3)
Dim yearno As Integer = dayofthursday.Year
Dim firstday As DateTime = "01-Jan-" & yearno.ToString

Dim totalweeks As Integer = 0

If firstday.DayOfWeek = DayOfWeek.Thursday Then
totalweeks = 53
ElseIf Date.IsLeapYear(yearno) = True _
And firstday.DayOfWeek = DayOfWeek.Wednesday Then
totalweeks = 53
Else
totalweeks = 52
End If

Return totalweeks
End Function

Tuesday, April 7, 2009

How to recover a database marked suspect?


SQL Server 2000/2005/2008
Recover database suspect sql server
The following script resets the status of the database and checks the database for integrity.

USE master;

GO

EXEC sp_resetstatus 'MYDATABASE';

GO

USE MYDATABASE;

DBCC CHECKDB WITH NO_INFOMSGS;

GO

SQL Server 2005/2008
Recover database marked suspect sql serve

USE master;

GO

ALTER DATABASE MYDATABASE SET EMERGENCY

GO

ALTER DATABASE MYDATABASE SET SINGLE_USER

GO

DBCC CHECKDB (MYDATABASE, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;

GO

USE MYDATABASE;

DBCC CHECKDB WITH NO_INFOMSGS;

GO

Friday, April 3, 2009

SQL Server 2005 - Get Size of Database and Individual Tables

-- Get size of Database
EXEC DATABASENAME.dbo.sp_spaceused

-- Get size of a Table in database
EXEC DATABASENAME.dbo.sp_spaceused 'TABLENAME'

-- Get size of All tables in a database
EXEC DATABASENAME.dbo.sp_spaceused '?'

-- Sql Query
USE DATABASENAME
GO
DECLARE @database_size DECIMAL(15,2)
SELECT @database_size = SUM(((convert (dec (15,2),[size]) * 8192 / 1048576)))
FROM dbo.sysfiles
PRINT @database_size

Thursday, April 2, 2009

Software Configuration Management (SCM)

Software Configuration Management (SCM) is part of configuration management (CM). Roger Pressman, in his book Software Engineering: A Practitioner's Approach, says that software configuration management (SCM) is a "set of activities designed to control change by identifying the work products that are likely to change, establishing relationships among them, defining mechanisms for managing different versions of these work products, controlling the changes imposed, and auditing and reporting on the changes made." In other words, SCM is a methodology to control and manage a software development project.

SCM concerns itself with answering the question: somebody did something, how can one reproduce it? Often the problem involves not reproducing "it" identically, but with controlled, incremental changes. Answering the question will thus become a matter of comparing different results and of analysing their differences. Traditional CM typically focused on controlled creation of relatively simple products. Nowadays, implementers of SCM face the challenge of dealing with relatively minor increments under their own control, in the context of the complex system being developed.

Variety of artifacts may be managed and versioned, including software code, documents, design models,and even the directory structure itself

The goals of SCM are generally:
Configuration Identification- What code are we working with?
Configuration Control- Controlling the release of a product and its changes.
Status Accounting- Recording and reporting the status of components.
Review- Ensuring completeness and consistency among components.
Build Management- Managing the process and tools used for builds.
Process Management- Ensuring adherence to the organization's development process.
Environment Management- Managing the software and hardware that host our system.
Teamwork- Facilitate team interactions related to the process.
Defect Tracking- making sure every defect has traceability back to the source

Wednesday, April 1, 2009

SQL - Update table A from table B

-- SIMPLE UPDATE QUERY FROM TABLE A TO B
UPDATE TABLEA
SET TABLEA.[NAME] = TABLEB.[NAME]
FROM TABLEB
WHERE TABLEB.ID = TABLEA.ID

-- USING JOINS
UPDATE TABLEA
SET TABLEA.[NAME] = TABLEB.[NAME]
FROM TABLEB
INNER JOIN TABLEC
ON TABLEC.FIELD1 = TABLEB.FIELD1
WHERE TABLEB.ID = TABLEA.ID

VB.Net - Get Directory / Folder Size


Public Function GetFolderSize(ByVal path As String, _
ByVal includeSubFolders As Boolean) As Long

GetFolderSize = 0

Dim main_dir As New System.IO.DirectoryInfo(path)
Dim dir_files() As FileInfo

If includeSubFolders Then
dir_files = main_dir.GetFiles("*", SearchOption.AllDirectories)
Else
dir_files = main_dir.GetFiles("*", SearchOption.TopDirectoryOnly)
End If

For Each ofile As IO.FileInfo In dir_files
GetFolderSize = GetFolderSize + ofile.Length
Next

End Function