Two odd behaviors with AutoCompleteExtenders I wanted to jot down before I forget.
If have want to set the focus on the textbox bound to the AutoCompleteExtender using JavaScript code (on pageLoad for example), the AutoCompleteExtender won't work
here's more on this and a solution
http://forums.asp.net/t/1397904.aspx
and here http://forums.asp.net/t/1220054.aspx
The other odd behavior is I think when we have a textbox with AutoCompleteExtender, the page tries to find the first input element with type = "submit" and selects such that if you hit enter that button will be clicked. I am not 100% sure, but I ran into this today.
I got around this by adding UseSubmitBehavior="false" property to all the buttons in the page. Doing so cause a problem, because some buttons had OnClientClick property populated and when their UseSubmitBehavior property set to false, they stopped submitting the form. The work around here is to submit the form using JavaScript code for example
asp:Button id="btnNew" runat="server" UseSubmitBehavior="false"
OnClientClick="if(validateForm()) this.form.submit();"
Friday, November 13, 2009
Thursday, November 12, 2009
Browser Programming
Using the new programming language Go http://golang.org/ from Google, it will be possible to run Go programs directly in browsers like Chrome. http://news.cnet.com/8301-30685_3-10395355-264.html?part=rss&subj=news&tag=2547-1_3-0-5
The question is how will web developers adopt this new approach?
The question is how will web developers adopt this new approach?
Monday, November 2, 2009
Script to Enable/Disable All Foreign Keys
To generate SQL statements which will disable all foreign key constraints in a database, you can use this script
select 'ALTER TABLE [' + s.name + '].[' + t.name + '] NOCHECK CONSTRAINT [' + fk.name +'];'
as script
from sys.foreign_keys fk inner join sys.tables t on fk.parent_object_id = t.object_id
inner join sys.schemas s on t.schema_id = s.schema_id
To enable foreign key the NOCKECK keyword needs to be changed to CHECK
If data was inserted when tables foreign keys were disabled and would like to check integrity,
DBCC CHECKCONSTRAINTS('TABLE_NAME') [WITH ALL_CONSTRAINTS] can be used
the optional WITH ALL_CONSTRAINT is used to include all constraints even the ones that are disabled even the ones
Here is a capture script from sql profile to see all foreign keys and their columns
SELECT
SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
tbl.name AS [Table_Name],
cstr.name AS [ForeignKey_Name],
fk.constraint_column_id AS [ID],
cfk.name AS [Name],
crk.name AS [ReferencedColumn]
FROM
sys.tables AS tbl
INNER JOIN sys.foreign_keys AS cstr ON cstr.parent_object_id=tbl.object_id
INNER JOIN sys.foreign_key_columns AS fk ON fk.constraint_object_id=cstr.object_id
INNER JOIN sys.columns AS cfk ON fk.parent_column_id = cfk.column_id and fk.parent_object_id = cfk.object_id
INNER JOIN sys.columns AS crk ON fk.referenced_column_id = crk.column_id and fk.referenced_object_id = crk.object_id
ORDER BY
[Table_Schema] ASC,[Table_Name] ASC,[ForeignKey_Name] ASC,[ID] ASC
select 'ALTER TABLE [' + s.name + '].[' + t.name + '] NOCHECK CONSTRAINT [' + fk.name +'];'
as script
from sys.foreign_keys fk inner join sys.tables t on fk.parent_object_id = t.object_id
inner join sys.schemas s on t.schema_id = s.schema_id
To enable foreign key the NOCKECK keyword needs to be changed to CHECK
If data was inserted when tables foreign keys were disabled and would like to check integrity,
DBCC CHECKCONSTRAINTS('TABLE_NAME') [WITH ALL_CONSTRAINTS] can be used
the optional WITH ALL_CONSTRAINT is used to include all constraints even the ones that are disabled even the ones
Here is a capture script from sql profile to see all foreign keys and their columns
SELECT
SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
tbl.name AS [Table_Name],
cstr.name AS [ForeignKey_Name],
fk.constraint_column_id AS [ID],
cfk.name AS [Name],
crk.name AS [ReferencedColumn]
FROM
sys.tables AS tbl
INNER JOIN sys.foreign_keys AS cstr ON cstr.parent_object_id=tbl.object_id
INNER JOIN sys.foreign_key_columns AS fk ON fk.constraint_object_id=cstr.object_id
INNER JOIN sys.columns AS cfk ON fk.parent_column_id = cfk.column_id and fk.parent_object_id = cfk.object_id
INNER JOIN sys.columns AS crk ON fk.referenced_column_id = crk.column_id and fk.referenced_object_id = crk.object_id
ORDER BY
[Table_Schema] ASC,[Table_Name] ASC,[ForeignKey_Name] ASC,[ID] ASC
Friday, October 2, 2009
Shrink Databases using sp_MSForEachDB
Using undocumented stored procedure sp_MSForEachDB and DBCC SHRINKDATABASE command you can shrink all databases on an SQL Server in one line of code
exec sp_MSForEachDB 'if ''?'' not in (select name from sys.databases where is_read_only = 1) DBCC SHRINKDATABASE([?]) '
You may need to add additional checks [skip offline dbs for example]. Test on SQL Server 2005.
exec sp_MSForEachDB 'if ''?'' not in (select name from sys.databases where is_read_only = 1) DBCC SHRINKDATABASE([?]) '
You may need to add additional checks [skip offline dbs for example]. Test on SQL Server 2005.
Wednesday, July 8, 2009
Wednesday, May 20, 2009
T-SQL Script to Generate SHRINKFILE statements for all DBs
This a t-sql script I use to generate DBCC SHRINKFILE statements for all databases on a SQL Server 2005/2008. Microsoft recommends that you change the recovery model to simple shrink the file and change back to full if the recovery model is full to begin with. You cannot shrink readonly dbs (or offile dbs obviously)
The script is provided AS IS.
use master;
GO
create procedure [dbo].[udp_genShrinkStatements] as begin
declare @sql nvarchar(max);
declare @filename varchar(256);
declare @dbid int;
declare @dbname varchar(256);
declare @recoveryModel int; -- 3 simple; 1 full
declare dbcursor cursor for SELECT database_id,[name], recovery_model --, recovery_model_desc
FROM sys.databases
WHERE (database_id > 4) AND (is_read_only = 0) and (state = 0) --skip system, readonly and offile dbs
ORDER BY [name]
open dbcursor;
set @sql = '';
fetch next from dbcursor into @dbid,@dbname,@recoveryModel;
while @@FETCH_STATUS = 0
begin
declare filecursor cursor for SELECT [name] from sys.sysaltfiles where dbid = @dbid;
open filecursor;
select @dbname = '['+@dbname+']';
--select @sql = @sql + @dbname;
-- print '--'+@dbname;
--select @sql = @sql + '--';
-- print 'USE ' + @dbname +';';
select @sql = @sql + 'USE ' + @dbname +';' ;
-- print 'GO';
--select @sql = @sql + ' GO ';
if @recoveryModel = 1
begin
-- print 'ALTER DATABASE '+@dbname +' SET RECOVERY SIMPLE WITH NO_WAIT;';
select @sql = @sql + 'ALTER DATABASE '+@dbname +' SET RECOVERY SIMPLE WITH NO_WAIT;';
end
fetch next from filecursor into @filename
while @@FETCH_STATUS = 0
begin
-- print 'DBCC SHRINKFILE('''+ @filename +''');';
select @sql = @sql + 'DBCC SHRINKFILE('''+ @filename +''');';
fetch next from filecursor into @filename
end
close filecursor
deallocate filecursor
if @recoveryModel = 1
begin
-- print 'ALTER DATABASE '+@dbname +' SET RECOVERY FULL WITH NO_WAIT;';
select @sql = @sql + 'ALTER DATABASE '+@dbname +' SET RECOVERY FULL WITH NO_WAIT;';
end
-- print '---------------';
--select @sql = @sql + '---------------';
fetch next from dbcursor into @dbid,@dbname,@recoveryModel;
end
close dbcursor;
deallocate dbcursor;
--exec sp_executesql @stmt = @sql;
SELECT @sql;
end
Tuesday, March 10, 2009
Report Builder 2.0 & Reporting Services 2008
We're still on reporting services 2005 but I've playing with Report Builder 2.0 in which you can see some of the features of Reporting Services 2008 such as the long-awaited control tablix. Very Nice! you can download it from here [http://www.microsoft.com/downloads/details.aspx?familyid=9f783224-9871-4eea-b1d5-f3140a253db6&displaylang=en] The builder looks really cool and the look-and-feel of Office 2007 and many more improvements of the VS Designer for RS 2005.
Of of most annoying bugs in 2005 was that when you make a change to a query in the report DataSet+ and save the report using CTRL+S (or click save icon), the DataTime parameters were converted to Strings. But so far I haven't seen this happening in RB 2008.
One way I worked around the bug I mentioned (DateTime converted to Strings) is by building the query after making the changes and before CTRL+S ( or saving).
Other welcomed additions to Reporting Services 2008 are the better charting capabilities and the Gauge controls.
Subscribe to:
Posts (Atom)