Link Unit
Tuesday, November 06, 2007
Redirect URI cannot contain newline characters
I was facing this problem while going through development of ASP.Net page.I was redirecting to an error page with an error message generated passed in query string. It is clear from the error that string cannot contain newline character. So I simply used System.HttpUtility.URLEncode(errString) and then passed it through querystring.
Failed to access IIS metabase problem
Possible Cause:-
When you install IIS AFTER .NET 2.0 framework, the rights of the ASPNET user had not been set correctly.
Resolution
Repair (Uninstall if repair does not work for you) .NET Framework 2.0
Simply run the following from command line to reset the IIS registry settings for aspnet user. Usually framework directory for .Net Framework 2.0 resides under %WindowsDir%\Microsoft.NET\Framework\v2.0.50727
%WindowsDir%\Microsoft.NET\Framework\v2.0.50727 > aspnet_regiis -i
When you install IIS AFTER .NET 2.0 framework, the rights of the ASPNET user had not been set correctly.
Resolution
Repair (Uninstall if repair does not work for you) .NET Framework 2.0
Simply run the following from command line to reset the IIS registry settings for aspnet user. Usually framework directory for .Net Framework 2.0 resides under %WindowsDir%\Microsoft.NET\Framework\v2.0.50727
%WindowsDir%\Microsoft.NET\Framework\v2.0.50727 > aspnet_regiis -i
Tuesday, October 23, 2007
DBLink Problem : TNS COULD NOT RESOLVE SERVICE NAME.
I was also facing the same problem when i create the DB Link as
CREATE PUBLIC DATABASE LINK TestService USING 'TestService';
TNS COULD NOT RESOLVE SERVICE NAME.
This is basically the problem with the TNSNAME.ora file, the 'Using' clause not able to find the service name in the TNSNAMES.ora
This is how i solved: I just copy paste the TestService`s Description part as
CODE
alter system set global_names=false
/
CREATE PUBLIC DATABASE LINK TestService
using
'(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = TestHost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TestService)
)
)
'
/
here my destination server host is TestHost & service name is TestService .
NOTE: If I had set the "GLOBAL_NAME" parameter to "TRUE", then the DBLink name need to be same as that of DBName .
CREATE PUBLIC DATABASE LINK TestService USING 'TestService';
TNS COULD NOT RESOLVE SERVICE NAME.
This is basically the problem with the TNSNAME.ora file, the 'Using' clause not able to find the service name in the TNSNAMES.ora
This is how i solved: I just copy paste the TestService`s Description part as
CODE
alter system set global_names=false
/
CREATE PUBLIC DATABASE LINK TestService
using
'(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = TestHost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TestService)
)
)
'
/
here my destination server host is TestHost & service name is TestService .
NOTE: If I had set the "GLOBAL_NAME" parameter to "TRUE", then the DBLink name need to be same as that of DBName .
Unrecongnised Section ConnectionStrings
When one of my client was deploying the web application he faced this issue. The following Steps helped me. Hope they help you too.
By default, when you create a website in IIS, the framework is 1.1
ASP.NET has introduced the new section in the web.config which will not be recognized in the .NET 1.1 framework.
1) Open IIS and browse to the website under computer_name > Web Sites > Default Web Site > website_name.
Where website_name is the actual name of the website, in this case the MySite website.
2) Right click website_name.
3) Click Properties.
4) Click the ASP.NET Tab
5) From the ASP.NET Version dropdown, select 2.0... version and Click OK.
Now, if you visit your application main page, it should work !
By default, when you create a website in IIS, the framework is 1.1
ASP.NET has introduced the new
1) Open IIS and browse to the website under computer_name > Web Sites > Default Web Site > website_name.
Where website_name is the actual name of the website, in this case the MySite website.
2) Right click website_name.
3) Click Properties.
4) Click the ASP.NET Tab
5) From the ASP.NET Version dropdown, select 2.0... version and Click OK.
Now, if you visit your application main page, it should work !
Wednesday, July 11, 2007
Delete Duplicate Rows
You may like to try these methods.
1. Add an idenity Column to the table
Alter table yourtable Add myseq int identity(1,1)
2. Delete all the rows where rows are duplicate based on the condition
Delete from yourTable where Exists ( Select 1 from YourTable B where Yourtable.column1=B.column1 and Yourtable.column2=B.column2 and Yourtable.myseq < B.myseq )
Or simple
1. Select distinct * into newTable from YourTable
2. delete from Yourtable
or
truncate table Yourtable
3. insert into Yourtable select * from newTable
1. Add an idenity Column to the table
Alter table yourtable Add myseq int identity(1,1)
2. Delete all the rows where rows are duplicate based on the condition
Delete from yourTable where Exists ( Select 1 from YourTable B where Yourtable.column1=B.column1 and Yourtable.column2=B.column2 and Yourtable.myseq < B.myseq )
Or simple
1. Select distinct * into newTable from YourTable
2. delete from Yourtable
or
truncate table Yourtable
3. insert into Yourtable select * from newTable
Tuesday, May 16, 2006
Union to make missing Operator INTERSECT,MINUS
SQL Server misses MINUS and INTERSECT , whereas in Oracle they are provided as part of the parcel.
But we can create the same effect of these operators using UNION and group by
Let us say we have two sets(tables) with same structure
StageShow(table)
RollNo int references Student
...
&
Sports(table)
RollNo int references Student
...
StageShow
1
2
5
....
Sports
1
3
5
.....
In Oracle Finding out MINUS and INTERSECT is easy by using the respective operator
i.e All students participating in both activities (although it can be a single activity table ,but just to show how we can implement I had done splitting )
Select Rollno from StageShow
Intersect
Select Rollno from Sports
Similarly we can say MINUS as
Select Rollno from StageShow
MINUS
Select Rollno from Sports
Now how to do it in SQL Server
How to implement INTERSECT ?
Select Rollno From (
Select 1 AS dummy,Rollno From StageShow
Union ALL
Select 2 AS dummy,Rollno From Sports
) X group By Rollno having count(*)=2
How to implement MINUS (A-B) Rows in A not in B?
Select Rollno From (
Select 1 AS dummy,Rollno From StageShow
Union ALL
Select 2 AS dummy,Rollno From Sports
) X group By Rollno having Max(Dummy)=1
But we can create the same effect of these operators using UNION and group by
Let us say we have two sets(tables) with same structure
StageShow(table)
RollNo int references Student
...
&
Sports(table)
RollNo int references Student
...
StageShow
1
2
5
....
Sports
1
3
5
.....
In Oracle Finding out MINUS and INTERSECT is easy by using the respective operator
i.e All students participating in both activities (although it can be a single activity table ,but just to show how we can implement I had done splitting )
Select Rollno from StageShow
Intersect
Select Rollno from Sports
Similarly we can say MINUS as
Select Rollno from StageShow
MINUS
Select Rollno from Sports
Now how to do it in SQL Server
How to implement INTERSECT ?
Select Rollno From (
Select 1 AS dummy,Rollno From StageShow
Union ALL
Select 2 AS dummy,Rollno From Sports
) X group By Rollno having count(*)=2
How to implement MINUS (A-B) Rows in A not in B?
Select Rollno From (
Select 1 AS dummy,Rollno From StageShow
Union ALL
Select 2 AS dummy,Rollno From Sports
) X group By Rollno having Max(Dummy)=1
Friday, May 12, 2006
Is Using Cursor Good?
We cannot avoid the usage of cursor in certain cases , but most of the
time appropriate where clauses can be used and hence cursor can be
avoided.
Let us take a simple example where a person's salary is to be increased
by 10% if his salary is <1000
and decrease by 10% if salary >=1000
If we use these two statements
Update emp set salary = salary *1.10 where salary <1000
Update emp set salary = salary *0.90 where salary >=1000
It will correctly update the salary of most but the one which fall in
the range ( 900-1100) would be afftected
So what normal procedural approach suugests. declare a cursor open cursor fetch row by row till @@fetch_status = 0 if salary <1000 then increase otherwise decrease for each row. close cursor
But with the introduction of 'case when' expression we can use
something like this
update emp set salary = salary * (case when salary<1000 then 1.10 else
0.90 end)
The only place I found it useful is where we need to do some DBA
activity. e.g truncate all tables (although it can be done with single
undocumented procedure 'sp_MSforeachtable' in SQL Server )
Exec sp_MSforeachtable 'truncate table ?' -- this will truncate all the
tables.
Cursor is like an evil beast we must learn to live without. Cursor is
not meant for DML activities. It should be used for DBA activities
only.
Conclusion: One must use the power given by the features not abuse them. Overusing
cursors for all activities means abusing the feature given.
time appropriate where clauses can be used and hence cursor can be
avoided.
Let us take a simple example where a person's salary is to be increased
by 10% if his salary is <1000
and decrease by 10% if salary >=1000
If we use these two statements
Update emp set salary = salary *1.10 where salary <1000
Update emp set salary = salary *0.90 where salary >=1000
It will correctly update the salary of most but the one which fall in
the range ( 900-1100) would be afftected
So what normal procedural approach suugests. declare a cursor open cursor fetch row by row till @@fetch_status = 0 if salary <1000 then increase otherwise decrease for each row. close cursor
But with the introduction of 'case when' expression we can use
something like this
update emp set salary = salary * (case when salary<1000 then 1.10 else
0.90 end)
The only place I found it useful is where we need to do some DBA
activity. e.g truncate all tables (although it can be done with single
undocumented procedure 'sp_MSforeachtable' in SQL Server )
Exec sp_MSforeachtable 'truncate table ?' -- this will truncate all the
tables.
Cursor is like an evil beast we must learn to live without. Cursor is
not meant for DML activities. It should be used for DBA activities
only.
Conclusion: One must use the power given by the features not abuse them. Overusing
cursors for all activities means abusing the feature given.
Subscribe to:
Posts (Atom)