tag:blogger.com,1999:blog-70736972540262900952024-03-18T04:03:59.616+01:00Problem SolvingASP.NET, SQL, XNA and More...kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.comBlogger69125tag:blogger.com,1999:blog-7073697254026290095.post-352972738563562512014-07-07T10:58:00.000+02:002014-07-07T10:58:15.945+02:00T-SQL: MDF files in useList the MDF file for every database in SQL Instance
<br />
<br />
<pre class="brush:sql">declare @files table (
db_name sysname,
physical_name nvarchar(260)
)
insert into @files
exec sp_MSforeachdb 'select "?", physical_name from ?.sys.database_files'
select db_name, physical_name
from @files
</pre>
kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-27577966536511955742014-07-02T09:17:00.001+02:002014-07-02T09:17:18.878+02:00T-SQL: Get a list of datesReturns a list of dates from first of year to end of year
<pre class="brush:sql">
DECLARE @startofyear DATETIME, @endofyear DATETIME
SET @startofyear = DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
SET @endofyear = DATEADD(yy, DATEDIFF(yy,0,getdate()) + 1, -1);
WITH sample AS (
SELECT @startofyear AS [Date]
UNION ALL
SELECT DATEADD(dd, 1, [Date])
FROM sample s
WHERE DATEADD(dd, 1, [Date]) <= @endofyear)
SELECT *
FROM sample
option (maxrecursion 370) –loop not more than 370, change to zero to infinite
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-16374153351193595692014-06-24T14:50:00.001+02:002014-06-24T14:50:19.277+02:00T-SQL: Search text inside tablesScript to search inside tables
<br />
<pre class="brush:sql">
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = 'STRING TO SEARCH'
CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)
WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)
IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO #Results
EXEC
(
'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
END
END
END
SELECT ColumnName, ColumnValue FROM #Results
</pre>
<br />
Link to <a href="http://geekswithblogs.net/rgupta/archive/2010/06/18/search-all-columns-in-all-tables-using-tsql.aspx" target="_blank">source</a>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-938664774367502462014-05-05T11:17:00.004+02:002014-05-05T11:17:43.008+02:00T-SQL: Remove duplicate rowsThe following example partitions the query by columns foo and bar and generates a number for each sequence containing the same 'foo' and 'bar'. Then using common table expressions 'WITH cte', which stores temporary the result set in a table named 'cte' (or whatever you choose) and then uses the script 'DELETE cte where [RN] > 1' to remove and duplicate entries having more than one result set with the same 'foo' and 'bar' combination. <br />
<br />
Be extra careful before using DELETE ;) I usually do a select query instead of a delete to see what I am about to delete and when i'm certain that the query is correct, I change it to a delete.<br />
<br />
<br />
<pre class="brush:sql">WITH cte AS (
SELECT[foo], [bar],
row_number() OVER(PARTITION BY foo, bar ORDER BY baz) AS [rn]
FROM TABLE
)
DELETE cte WHERE [rn] > 1
</pre>
Source<br />
<a href="http://stackoverflow.com/questions/6025367/t-sql-deleting-all-duplicate-rows-but-keeping-one">http://stackoverflow.com/questions/6025367/t-sql-deleting-all-duplicate-rows-but-keeping-one</a>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-28113939976246766402014-01-10T14:38:00.001+01:002014-01-10T14:38:37.781+01:00T-SQL: Return nth delimited element from a string<br />
<pre class="brush:sql">CREATE FUNCTION [dbo].[fn_String_SplitByDelimiter]
(
@List VARCHAR(MAX),
@Delimiter VARCHAR(255),
@ElementNumber int
)
RETURNS VARCHAR(4000)
AS
BEGIN
DECLARE @result varchar(4000)
DECLARE @Items TABLE ( position int IDENTITY PRIMARY KEY,
Item VARCHAR(4000)
)
DECLARE @ll INT , @ld INT;
set @ll = LEN(@List) + 1
set @ld = LEN(@Delimiter);
WITH a AS
(
SELECT
[start] = 1,
[end] = COALESCE(NULLIF(CHARINDEX(@Delimiter,
@List, @ld), 0), @ll),
[value] = SUBSTRING(@List, 1,
COALESCE(NULLIF(CHARINDEX(@Delimiter,
@List, @ld), 0), @ll) - 1)
UNION ALL
SELECT
[start] = CONVERT(INT, [end]) + @ld,
[end] = COALESCE(NULLIF(CHARINDEX(@Delimiter,
@List, [end] + @ld), 0), @ll),
[value] = SUBSTRING(@List, [end] + @ld,
COALESCE(NULLIF(CHARINDEX(@Delimiter,
@List, [end] + @ld), 0), @ll)-[end]-@ld)
FROM a
WHERE [end] < @ll
)
INSERT @Items SELECT [value]
FROM a
WHERE LEN([value]) > 0
OPTION (MAXRECURSION 0);
SELECT @result=Item
FROM @Items
WHERE position=@ElementNumber
RETURN @result;
END
</pre>
Example<br />
<pre class="brush:sql">SELECT [dbo].fn_String_SplitByDelimiter (
'1ST\2ND\3RD\4TH'
,'\'
,3)
</pre>
<br />
Will output
<br />
3RD<br />
<br />
taken from the below url, just updated it to work on SQL2005<br />
http://stackoverflow.com/questions/19449492/using-t-sql-return-nth-delimited-element-from-a-string<br />
<br />kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-77170174807114607202014-01-06T15:53:00.000+01:002014-01-06T16:00:25.414+01:00T-SQL: Which table taking most spaceThis query will list all tables of the selected database, sorted by the table which is taking up most data space in MB from the database. I used it on a database which had a huge MDF file and found out that the Audit table had grown too much.<br />
<br />
<pre class="brush:sql">SELECT
t.NAME AS TableName,
i.name AS indexName,
SUM(p.rows) AS RowCounts,
SUM(a.total_pages) AS TotalPages,
SUM(a.used_pages) AS UsedPages,
SUM(a.data_pages) AS DataPages,
(SUM(a.total_pages) * 8) / 1024 AS TotalSpaceMB,
(SUM(a.used_pages) * 8) / 1024 AS UsedSpaceMB,
(SUM(a.data_pages) * 8) / 1024 AS DataSpaceMB
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
WHERE
t.NAME NOT LIKE 'dt%' AND
i.OBJECT_ID > 255 AND
i.index_id <= 1
GROUP BY
t.NAME, i.object_id, i.index_id, i.name
ORDER BY
TotalSpaceMB desc
--OBJECT_NAME(i.object_id) </pre>
<pre class="brush:sql"></pre>
<br />
Source: <a href="http://stackoverflow.com/questions/3927231/how-can-you-tell-what-tables-are-taking-up-the-most-space-in-a-sql-server-2005-d">http://stackoverflow.com/questions/3927231/how-can-you-tell-what-tables-are-taking-up-the-most-space-in-a-sql-server-2005-d</a>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-5438780456332050522013-11-27T17:26:00.001+01:002013-11-27T17:26:20.000+01:00Run Visual Studio as an Administrator in Windows 8<div class="MsoNormal" style="background: white; line-height: 13.5pt; vertical-align: baseline;">
<span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">In Windows 8,
you have to right-click </span><span lang="EN-GB" style="background-color: #eeeeee; background-position: initial initial; background-repeat: initial initial; border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;">devenv.exe</span><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;"> and select "Troubleshoot
compatibility".<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">1.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">select "Troubleshoot program"<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">2.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">check "The program requires additional
permissions"<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">3.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">click "Next", click "Test the
program..."<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">4.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">wait for the program to launch<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">5.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">click "Next"<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">6.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">select "Yes, save these settings for this
program"<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<!--[if !supportLists]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">7.<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;">
</span></span><!--[endif]--><span lang="EN-GB" style="font-family: Arial, sans-serif; font-size: 10.5pt;">click "Close"</span></div>
<div class="MsoNormal" style="line-height: 13.5pt; margin-left: 22.5pt; mso-list: l0 level1 lfo1; tab-stops: list .5in; text-indent: -.25in; vertical-align: baseline;">
<br /></div>
<br />
<div class="MsoNormal">
<span lang="EN-GB"><a href="http://stackoverflow.com/questions/12257110/can-you-force-visual-studio-to-always-run-as-an-administrator-in-windows-8">http://stackoverflow.com/questions/12257110/can-you-force-visual-studio-to-always-run-as-an-administrator-in-windows-8</a><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If you are getting the error 'Unable to debug the server' when trying to debug a solution, try running visual studio as administrator. The above forces Visual Studio to always run as administrator so you won't get this error again</div>
kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-60222635044226699432013-09-30T09:53:00.001+02:002013-09-30T09:53:38.538+02:00T-SQL: List all table foreign keys<pre class="brush:sql">SELECT f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,
fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,
fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
</pre>
kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-46732022474614203762013-06-27T08:58:00.000+02:002013-06-27T08:58:19.421+02:00Find number of active SQL connections and kill them<h3>
How to find number of active SQL connections</h3>
<br />
<pre class="brush:sql">select
db_name(dbid) as [Database Name],
count(dbid) as [No Of Connections],
loginame as [Login Name]
from
sys.sysprocesses
where
dbid > 0
group by
dbid, loginame
</pre>
<h3>
How to kill active SQL connections to a single database</h3>
<pre class="brush:sql">set nocount on
declare @databasename varchar(100)
declare @query varchar(max)
set @query = ''
set @databasename = 'My database'
if db_id(@databasename) < 4
begin
print 'system database connection cannot be killeed'
return
end
select @query=coalesce(@query,',' )+'kill '+convert(varchar, spid)+ '; '
from master..sysprocesses where dbid=db_id(@databasename)
if len(@query) > 0
begin
print @query
exec(@query)
end
</pre>
Link to article<br />
<a href="http://www.codeproject.com/Articles/389725/How-to-find-the-active-SQL-connections-and-kill-th">http://www.codeproject.com/Articles/389725/How-to-find-the-active-SQL-connections-and-kill-th</a>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-7538938577399269202013-02-26T22:02:00.002+01:002013-02-26T22:02:14.161+01:00T-SQL: Get current date and timeFunctions available to get the current date and time<br />
<div>
<br /></div>
<table border="1" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<th>Function
</th>
<th>Result
</th>
<th>Return type
</th>
</tr>
<tr>
<td>GETDATE()
</td>
<td>2013-02-26 20:54:24.057
</td>
<td>DATETIME
</td>
</tr>
<tr>
<td>CURRENT_TIMESTAMP
</td>
<td>2013-02-26 20:54:24.057
</td>
<td>DATETIME
</td>
</tr>
<tr>
<td>GETUTCDATE()</td>
<td>2013-02-26 20:09:17.467
</td>
<td>DATETIME
</td>
</tr>
<tr>
<td>SYSDATETIME()</td>
<td>2013-02-26 21:09:17.4680514
</td>
<td>DATETIME2
</td>
</tr>
<tr>
<td>SYSUTCDATETIME()</td>
<td>2013-02-26 20:09:17.4680514
</td>
<td>DATETIME2
</td>
</tr>
<tr>
<td>SYSDATETIMEOFFSET()</td>
<td>2013-02-26 21:09:17.4680514 +01:00
</td>
<td>DATETIMEOFFSET
</td>
</tr>
</tbody>
</table>
<br />
UTC means Coordinated Universal Time and is widely used as time standard in web applications. The result above were taken on a PC with the time zone (UTC+01:00). Note that the UTC functions return the time one hour before the rest. <br />
<br />
CURRENT_TIMESTAMP is the recommended one as it is the ANSI equivalent of GETDATE()<br />
<br />
Don't forget that if you only need the current DATE or TIME, you can cast the return of the above functions to a DATE or TIME<br />
<br />
Example: <br />
<br />
SELECT CAST(GETDATE() as DATE)<br />
<br />
which will return<br />
<br />
2013-02-26<br />
<br />
For all DateTime functions visit the following <a href="http://msdn.microsoft.com/en-us/library/ms186724(v=sql.105).aspx" target="_blank">link</a>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-86526369340754780362013-01-21T17:22:00.002+01:002013-01-21T17:22:58.373+01:00ASP.NET: How to check ViewState sizeJust enter the following code in the console of firebug or chrome developer tools and press Enter. Or call the code upon a button click
<pre class="brush:javascript">
alert("View state is " + document.forms[0]["__VIEWSTATE"].value.length+ " bytes");
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-16180353747347094502012-10-31T10:44:00.000+01:002012-10-31T10:44:08.128+01:00Get querystring parameter by Javascript<pre class="brush:javascript">
function queryString(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i = 0; i < gy.length; i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-60130145620709352072012-10-23T12:32:00.000+02:002012-10-23T12:32:51.374+02:00Error: Object must implement IConvertibleWhen passing a Guid parameter to an SqlDatasource, you should not define the Type.<br />
<br />
<pre class="brush:csharp"><insertparameters>
<asp:parameter direction="Input" name="co_pk" type="Int64">
<asp:parameter direction="Input" name="co_Guid">
</asp:parameter></asp:parameter></insertparameters>
</pre>
<br />
At first I tried using the type "String", but that caused the error<br />
<br />
<span style="color: red;">Object must implement IConvertible</span><br />
<br />
<br />kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-83446257029200608272012-08-18T10:56:00.002+02:002012-08-18T10:56:44.412+02:00Setting Culture in ASP.NET<h2>
Difference between Culture and UICulture</h2>
<br />
Culture defines culture dependent objects like currency, date, currency and number formatting. This can only defined using a specific culture (ex: en-GB not en)<br />
<br />
UICulture defines which resources (local and global) will be loaded for this page. Both neutral and specific cultures.<br />
<br />
<h2>
Setting Culture dynamically at runtime</h2>
<br />
Culture and UICulture need to be set in the InitializeCulture event<br />
<br />
<br />
<pre class="brush:csharp">protected override void InitializeCulture()
{
if (Request.Form["DropDownList1"] != null)
{
//can be neutral i.e. en or en-GB
UICulture = Request.Form["DropDownList1"];
//requires a specific culture ex: de-DE
Culture = Request.Form["DropDownList1"];
}
base.InitializeCulture();
}
</pre>
kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-757555694865488872012-08-01T10:28:00.000+02:002012-08-01T10:28:52.286+02:00Return nth index of a delimited string in TSQL<pre class="brush:sql">
CREATE FUNCTION [dbo].[fn_SplitSelect] (@sep VARCHAR(32), @s VARCHAR(MAX), @index INT)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @xml XML
SET @XML = N'<root><r>' + REPLACE(@s, @sep, '</r><r>') + '</r></root>'
DECLARE @ret NVARCHAR(MAX)
SELECT @ret = Item
FROM (
SELECT r.value('.','VARCHAR(5)') as Item, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS rownum
FROM @xml.nodes('//root/r') AS RECORDS(r)
) t
WHERE t.rownum = @index
RETURN @ret
END
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-43782396558247130302012-07-27T10:13:00.000+02:002012-07-27T10:13:39.622+02:00T-SQL: Script to enter list of coloursI couldn't find a list, so i created one from the list of colours used by HTML. Enjoy :) Does anybody know of a website where you can find these kind of scripts?
<br />
<pre class="brush:csharp">/****** Object: Table [dbo].[Colours] Script Date: 07/27/2012 10:07:49 ******/
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'AliceBlue ', N'#F0F8FF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'AntiqueWhite ', N'#FAEBD7')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Aqua ', N'#00FFFF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Aquamarine ', N'#7FFFD4')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Azure ', N'#F0FFFF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Beige ', N'#F5F5DC')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Bisque ', N'#FFE4C4')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Black ', N'#000000')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'BlanchedAlmond ', N'#FFEBCD')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Blue ', N'#0000FF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'BlueViolet ', N'#8A2BE2')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Brown ', N'#A52A2A')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'BurlyWood ', N'#DEB887')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'CadetBlue ', N'#5F9EA0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Chartreuse ', N'#7FFF00')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Chocolate ', N'#D2691E')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Coral ', N'#FF7F50')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'CornflowerBlue ', N'#6495ED')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Cornsilk ', N'#FFF8DC')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Crimson ', N'#DC143C')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Cyan ', N'#00FFFF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkBlue ', N'#00008B')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkCyan ', N'#008B8B')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkGoldenRod ', N'#B8860B')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkGray ', N'#A9A9A9')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkGrey ', N'#A9A9A9')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkGreen ', N'#006400')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkKhaki ', N'#BDB76B')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkMagenta ', N'#8B008B')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkOliveGreen ', N'#556B2F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Darkorange ', N'#FF8C00')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkOrchid ', N'#9932CC')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkRed ', N'#8B0000')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkSalmon ', N'#E9967A')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkSeaGreen ', N'#8FBC8F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkSlateBlue ', N'#483D8B')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkSlateGray ', N'#2F4F4F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkSlateGrey ', N'#2F4F4F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkTurquoise ', N'#00CED1')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DarkViolet ', N'#9400D3')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DeepPink ', N'#FF1493')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DeepSkyBlue ', N'#00BFFF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DimGray ', N'#696969')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DimGrey ', N'#696969')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'DodgerBlue ', N'#1E90FF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'FireBrick ', N'#B22222')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'FloralWhite ', N'#FFFAF0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'ForestGreen ', N'#228B22')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Fuchsia ', N'#FF00FF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Gainsboro ', N'#DCDCDC')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'GhostWhite ', N'#F8F8FF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Gold ', N'#FFD700')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'GoldenRod ', N'#DAA520')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Gray ', N'#808080')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Grey ', N'#808080')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Green ', N'#008000')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'GreenYellow ', N'#ADFF2F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'HoneyDew ', N'#F0FFF0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'HotPink ', N'#FF69B4')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'IndianRed ', N'#CD5C5C')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Indigo ', N'#4B0082')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Ivory ', N'#FFFFF0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Khaki ', N'#F0E68C')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Lavender ', N'#E6E6FA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LavenderBlush ', N'#FFF0F5')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LawnGreen ', N'#7CFC00')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LemonChiffon ', N'#FFFACD')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightBlue ', N'#ADD8E6')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightCoral ', N'#F08080')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightCyan ', N'#E0FFFF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightGoldenRodYellow ', N'#FAFAD2')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightGray ', N'#D3D3D3')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightGrey ', N'#D3D3D3')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightGreen ', N'#90EE90')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightPink ', N'#FFB6C1')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightSalmon ', N'#FFA07A')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightSeaGreen ', N'#20B2AA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightSkyBlue ', N'#87CEFA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightSlateGray ', N'#778899')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightSlateGrey ', N'#778899')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightSteelBlue ', N'#B0C4DE')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LightYellow ', N'#FFFFE0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Lime ', N'#00FF00')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'LimeGreen ', N'#32CD32')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Linen ', N'#FAF0E6')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Magenta ', N'#FF00FF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Maroon ', N'#800000')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumAquaMarine ', N'#66CDAA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumBlue ', N'#0000CD')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumOrchid ', N'#BA55D3')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumPurple ', N'#9370D8')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumSeaGreen ', N'#3CB371')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumSlateBlue ', N'#7B68EE')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumSpringGreen ', N'#00FA9A')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumTurquoise ', N'#48D1CC')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MediumVioletRed ', N'#C71585')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MidnightBlue ', N'#191970')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MintCream ', N'#F5FFFA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'MistyRose ', N'#FFE4E1')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Moccasin ', N'#FFE4B5')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'NavajoWhite ', N'#FFDEAD')
GO
print 'Processed 100 total records'
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Navy ', N'#000080')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'OldLace ', N'#FDF5E6')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Olive ', N'#808000')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'OliveDrab ', N'#6B8E23')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Orange ', N'#FFA500')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'OrangeRed ', N'#FF4500')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Orchid ', N'#DA70D6')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PaleGoldenRod ', N'#EEE8AA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PaleGreen ', N'#98FB98')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PaleTurquoise ', N'#AFEEEE')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PaleVioletRed ', N'#D87093')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PapayaWhip ', N'#FFEFD5')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PeachPuff ', N'#FFDAB9')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Peru ', N'#CD853F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Pink ', N'#FFC0CB')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Plum ', N'#DDA0DD')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'PowderBlue ', N'#B0E0E6')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Purple ', N'#800080')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Red ', N'#FF0000')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'RosyBrown ', N'#BC8F8F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'RoyalBlue ', N'#4169E1')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SaddleBrown ', N'#8B4513')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Salmon ', N'#FA8072')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SandyBrown ', N'#F4A460')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SeaGreen ', N'#2E8B57')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SeaShell ', N'#FFF5EE')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Sienna ', N'#A0522D')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Silver ', N'#C0C0C0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SkyBlue ', N'#87CEEB')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SlateBlue ', N'#6A5ACD')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SlateGray ', N'#708090')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SlateGrey ', N'#708090')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Snow ', N'#FFFAFA')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SpringGreen ', N'#00FF7F')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'SteelBlue ', N'#4682B4')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Tan ', N'#D2B48C')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Teal ', N'#008080')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Thistle ', N'#D8BFD8')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Tomato ', N'#FF6347')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Turquoise ', N'#40E0D0')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Violet ', N'#EE82EE')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Wheat ', N'#F5DEB3')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'White ', N'#FFFFFF')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'WhiteSmoke ', N'#F5F5F5')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'Yellow ', N'#FFFF00')
INSERT [dbo].[Colours] ([Colour], [Code]) VALUES (N'YellowGreen ', N'#9ACD32')
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-2650325343378522582012-07-25T22:58:00.002+02:002012-07-25T22:58:17.055+02:00Using Resource Files in ASP.NETThere are 2 types of resource files, local and global resource files. Local resource files are used for a specific page, while global resources can be used throughout a site.<br />
<br />
<h2>
Local Resource files</h2>
<br />
Local resource files must be stored in the ASP.NET folder App_LocalResources. These files have the extension .resx and must be named like the page. If the page is named About.aspx, then the resource page will be About.aspx.resx. This will be the default resource file for the page. In order to create a resource file for another language, you will need to create another file with the language 2 letter ISO code. If you need resources for the German language for example, the file will need to be named About.aspx.de.resx. You can also use specific languages like About.aspx.en-GB.resx<br />
<br />
<h3>
Implicit Localization</h3>
<br />
To easiest way to create a resource file, is to use the tool provided in Visual Studio. From the Tools menu, select Generate Local Resource. This will create a resource file for the form you are viewing.<br />
<br />
The tool will generate resource keys for every string property for every control<br />
<br />
<pre class="brush:csharp"><asp:button id="Button1" meta:resourcekey="Button1" runat="server" text="DefaultText"></asp:button></pre>
<br />
<h3>
Explicit Localization</h3>
<br />
In explicit localization, you can manually attach a resource to a control's property like so<br />
<br />
<pre class="brush:csharp"> <asp:button cssclass="submitButton" id="ButtonFind" runat="server" text="<%$ Resources:, ButtonFindResource1.Text %>"></asp:button></pre>
<h2>
Global Resource files</h2>
<br />
Global resource files are stored in the App_GlobalResources ASP.NET folder. Use these resources for text which will be used more than once in your website. I typically use it for common words such as 'Save', 'Edit', 'Delete', etc.. These files also have the .resx extension. In order to use them from mark up, use the same syntax as the explicit localization mentioned above<br />
<br />
<pre class="brush:csharp"><asp:label id="LocalizeWelcome" runat="server" text="<%$ Resources:SharedLocalizedText, WelcomeString %>"></asp:label>
</pre>
<h2>
Using and accessing resources programmatically</h2>
<br />
There are 2 ways to retrieve values at runtime. If the global resources are available in your project you can use the following syntax which also provides intellisense<br />
<pre class="brush:csharp">string myText = Resources.SharedLocalizedText.WelcomeText;
</pre>
If the file is not available at design time, you can use the following method
<br />
<pre class="brush:csharp">string myText = Convert.ToString(GetGlobalResourceObject("MyGlobalResourceFile", "WelcomeText"));
</pre>
<br />
The first parameter is the name of the global resource file (without the extension) and the second is the resource key which you want to retrieve from the filekevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-76261403925394196562012-06-21T21:39:00.000+02:002012-06-21T21:39:39.703+02:00Using Cache in ASP.NET<br />
<pre class="brush:csharp">if (Cache["Name"] != null)
Label1.Text = "Hello," + (string)Cache["Name"];
else
Label1.Text = "Hello, guest! ";
</pre>
<br />
<br />
Setting Cache Expiry<br />
<br />
<br />
<pre class="brush:csharp">Cache.Insert("Name", "Kevin", null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-73393727236227662442012-06-14T12:44:00.001+02:002012-06-14T12:44:44.111+02:00How to: Add CSS file in ASP.NET at runtimeAdding CSS file in ASP.NET programatically
<br />
<br />
<pre class="brush:csharp">HtmlGenericControl si = new HtmlGenericControl();
si.TagName = "link";
si.Attributes.Add("type", "text/css");
si.Attributes.Add("href", "css/module.css");
si.Attributes.Add("rel", "stylesheet");
this.Page.Header.Controls.Add(si);
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-47829390826393453812012-06-12T07:34:00.001+02:002012-07-14T16:04:31.276+02:00Themes<h2>
Creating a theme</h2>
<br />
Themes should be defined in the special App_Themes folder.<br />
<br />
<ol>
<li>Right-click your website in Solution Explorer, click Add ASP.NET Folder, and then click Theme.</li>
<li>Within the App_Themes folder, you define an individual folder for each theme in your application. Example: Professional or Simple</li>
</ol>
<br />
You can then create skin files or style sheets in each of these theme folders.<br />
<br />
<h2>
Applying the theme</h2>
<br />
This can be done either on the page level by using the attributes Theme or StyleSheetTheme in the @Page directive. The difference between Theme and StyleSheetTheme is that StyleSheetTheme sets properties before the page's controls properties are set, while Theme properties are set after the page sets the controls properties. <br />
<br />
This means that if in the theme folder, we have set the label colour to Red and in the page we set the label colour to Green, the label will be red if using Theme but green if using StyleSheetTheme.<br />
<br />
Or as commonly used, apply it to the whole website through the web.config in the system.web section<br />
<br />
<pre class="brush:csharp"><pages Theme=”themeName”>
or
<pages StyleSheetTheme=”themeName”>
</pre>
<br />
<h2>
Changing theme at runtime programattically</h2>
<br />
In order to change the theme by code, use the PreInit event to change either the 'Theme' of the page. If you want that the user changes the theme upon a button click or a change in dropdown, just store the value in a session variable, and then set the session variable's value to the page.theme in the preinit event<br />
<br />
<pre class="brush:csharp">protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = "Simple";
}
</pre>
<br />
To change StyleSheetTheme at runtime, you can't do the same as the above or you will get the error<br />
<br />
<span style="color: red;">The StyleSheetTheme property cannot be set, please override the property instead.
</span><br />
<br />
In order to apply the StyleSheetTheme at runtime, you must override the property like so:<br />
<br />
<br />
<pre class="brush:csharp">
public override String StyleSheetTheme
{
get { return "Simple"; }
}
</pre>
Ideally, use the above code in a base page which all your pages derive from.kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-56831467878208584542012-06-11T22:11:00.000+02:002012-06-14T12:46:18.955+02:00Batch file to restart IIS service<br />
<div class="MsoNormal" style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Batch file to restart service</div>
<div class="MsoNormal" style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div class="MsoNormal" style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;">
net stop "IIS Admin Service"<u></u><u></u></div>
<div class="MsoNormal" style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;">
net start "IIS Admin Service"</div>
<div class="MsoNormal" style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div class="MsoNormal" style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;">
You can change the name in the quotes to whatever other service. If you run it manually, make sure to "Run it as administrator". If you are using it in a scheduled task, you will need to give it the necessary permissions<br />
<br />
[EDIT]<br />
If you get:<br />
The following services are dependent on the IIS Admin Service service. Stopping the IIS Admin Service service will also stop these services.<br />
<br />
World Wide Web Publishing Service<br />
HTTP SSL<br />
<br />
Do you want to continue this operation? (Y/N)<br />
<br />
Then edit the batch file to include another parameter for this choice<br />
<br />
<br />
<div class="MsoNormal">
net stop "IIS Admin Service" /yes<u></u><u></u></div>
<div class="MsoNormal">
net start "IIS Admin Service"<br />
<br />
[EDIT 2]<br />
Apparently using the above will sometimes stop all websites</div>
</div>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-317850026555165312012-06-06T12:07:00.002+02:002012-06-06T12:07:18.600+02:00ASPxSpinEdit validation: number greater than 0The only way I could find is to use the client-side validation event<br />
<pre class="brush:csharp"><dxe:aspxspinedit clientinstancename="txtQtyToInvoice" height="21px" id="txtQtyToInvoice" runat="server">
<validationsettings display="Dynamic" errordisplaymode="ImageWithTooltip" validationgroup="additem"></validationsettings>
<clientsideevents validation="function(s,e){if(e.value <=0 ) {e.isValid=false;}}">
</clientsideevents></dxe:aspxspinedit>
</pre>
or use regex if you find a good expressionkevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-87586474009061102742012-06-02T17:37:00.001+02:002012-06-02T17:37:49.019+02:00Using Master Pages in ASP.NET 4<h2>
Master Pages</h2>
<br />
Master pages contain a different page directive from normal pages. Instead of @Page, masterpages have @Master.<br />
<br />
<pre class="brush:csharp"><%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
</pre>
<br />
The Master page must have a contentplaceholder tag, where the pages deriving from this page will be inserted.<br />
<br />
<pre class="brush:csharp"><asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</pre>
<br />
<h2>
Content Pages</h2>
<br />
When creating a new page, you can derive from a selected Master Page by ticking 'Select master page'. After clicking 'Add', you will be prompted to select the masterpage from your website.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBPFrfn1QepoWMFx99raw9AEp0w7-P9s5CrNXXcabhmKLOAi8D56dYkVzi54mcuShcx4Tn-xb8kZTEM3kOguttIaGvoymnynUkydE51g8sJ7pHfAGkR0EIp6O-cioLF3q92Z_Nl4PkIvKk/s1600/Masterpage.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBPFrfn1QepoWMFx99raw9AEp0w7-P9s5CrNXXcabhmKLOAi8D56dYkVzi54mcuShcx4Tn-xb8kZTEM3kOguttIaGvoymnynUkydE51g8sJ7pHfAGkR0EIp6O-cioLF3q92Z_Nl4PkIvKk/s400/Masterpage.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Adding a web page with master page</td></tr>
</tbody></table>
You can also do this by adding the following attribute in the @Page directive of the content page:<br />
<br />
<pre class="brush:csharp"><%@ Page Title="About Us" Language="C#" <b>MasterPageFile="~/Site.master"</b> AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %>
</pre>
<br />
This can also be done throughout the website by defining the masterpage in the pages element in the Web.config file. Any content pages that do not have the contentplaceholder will not apply the master page.<br />
<br />
<pre class="brush:xml"><system.web>
<pages masterPageFile="~/Site.master" />
</system.web></pre>
<br />
You can also change the page title from the content page by using the Title attribute in the Page directive.<br />
<br />
The content page must contain a content control. The markup written in this control will eventually be rendered in the contentplaceholder (with the same id) of the masterpage. You can have multiple content controls in a content page, as long as there are the same number of contentplaceholders in the masterpage<br />
<br />
<pre class="brush:csharp"><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
About
</h2>
<p>
Put content here.
</p>
</asp:Content></pre>
<br />
Note that the content place holder cannot be nested in other controls or tags or otherwise you will get the following error. Same happens if there is no content placeholder in a content page.<br />
<br />
<h2 style="background-color: white; color: maroon; font-family: Verdana; font-size: 14pt; font-weight: normal;">
<i>Content controls have to be top-level controls in a content page or a nested master page that references a master page.</i></h2>
<br />
Note: Setting the EnableViewState property on the content page to true but setting the same property<br />
to false in the master page, will result in having view state disabled because the setting on the<br />
master page takes priority.<br />
<br />
<h3>
Getting controls from the Master Page</h3>
In order to get a control inside the master page from the content page you can use the FindControl method of the Master page property:<br />
<br />
<pre class="brush:csharp">this.Master.FindControl("HeadLoginView") as LoginView;</pre>
<br />
<h3>
Getting data from the Master Page</h3>
If you need a property from the master page, you will need to reference the master page in the content page by using the @MasterType directive<br />
<br />
<pre class="brush:csharp"><%@ MasterType VirtualPath="~/Site.master" %></pre>
<br />
Then from the content page, we can access the property that we need<br />
<br />
<pre class="brush:csharp">lblUser.Text = this.Master.CurrentUser;
</pre>
<br />
<h3 style="font-family: 'Times New Roman'; white-space: normal;">
Changing Master Page dynamically</h3>
<br />
<pre class="brush:csharp">protected void Page_PreInit(object sender, EventArgs e)
{
this.MasterPageFile = String.Format("~/{0}.master", "Site2");
}
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-18691067024123494992012-05-16T17:23:00.002+02:002012-05-16T17:23:34.093+02:00T-SQL: Select node value from xml columnSQL Code:<br />
<br />
Column name is wau_xml
<br />
<br />
<pre class="brush:sql">SELECT wau_xml.value('(/Document/VersionNo)[1]', 'int') FROM Table
</pre>
<br />
XML in column:
<br />
<br />
<pre class="brush:xml"><Document>
<VersionNo>1</VersionNo>
</Document>
</pre>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0tag:blogger.com,1999:blog-7073697254026290095.post-46246494990641907992012-04-19T10:40:00.002+02:002012-04-19T10:40:16.766+02:00Error: A connection was successfully established with the server, but then an error occurred during the pre-login handshakeThe local machine suddenly started giving me the error<br />
<br />
<h2 style="background-color: white; color: maroon; font-family: Verdana; font-size: 14pt; font-weight: normal;">
<i>A connection was successfully established with the server, but then an error occurred during the pre-login handshake</i></h2>
In order to solve it, try the following<br />
<br />
<br />
<ol>
<li>Clean your Visual Studio solution</li>
<li>Rebuild project</li>
<li>Reset IIS</li>
<li>Run the project again</li>
</ol>
<div>
This did the trick for me</div>kevohttp://www.blogger.com/profile/08183986049777704309noreply@blogger.com0