Archive for the ‘Tips and Tricks’ Category
Visual Studio 2005 – Compile Options
In Visual Studio 2005, .pdb file gets generated in Debug mode and Release mode.
In debug mode it loads the entire symbol table, in Release mode it loads the key symbols.
In Release mode, the generated .pdb can be deleted very well deleted. (Because framework does not uses it)
To disable .pdb generation in Release mode, goto
Project Properties > Compile Tab > Advanced Compile Options
Goto Generate Debug Info (dropdown list) and select None.
Step 1: Create a link between two servers
Goto Query Window
EXEC sp_addlinkedserver 'PRODSVR', N'SQL Server' GO
‘PRODSVR’ is the name of the Server.Execute it.
Step 2: Setup Permission between Servers.In Management StudioGotoServer Object >> Linked Servers >>
PRODSVR (See Image)
Right Click on PRODSVR goto Properties and make changes as given below.
Step 3: To access the tables in other server
Use the following hirearchy
To access Person.Address table from AdventureWorks database
Select * From PRODSVR.AdventureWorks.Person.Address
1. Update Production server with data from development server. (SSIS is alternate way)
2. Allow users to access production database without multiple logins. (windows authentication or SQL authentication)
(Copied from Moses’s Blog for my reference)
Well, I had a small issue regarding writing a script to clean a database we have and reset its identity columns in all tables. Although the database wasn’t huge one (less than 100 tables) I had to trace relations to be able to delete child table’s records before parent’s ones because of the foreign key constraints. The solution is disable the foreign keys and delete records with no fear of any errors then enables the constraints again.
Well, I found a solution to disable all constraints without the need to go on each table and disable it manually. and I was happy to know that I can use this solution in deleting all records from all tables. Not only this I was able to use the same solution to reset identity columns in all tables.
The solution was to use this built in stored procedure sp_MSforeachtable. For help about this proc search for it in Books online or use this sp_helptext sp_MSForeachtable.
Now back to my 6 lines, bellow is how I re-zeroed my Database:
1: /*Disable Constraints & Triggers*/ 2: exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' 3: exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL' 4: 5: /*Perform delete operation on all table for cleanup*/ 6: exec sp_MSforeachtable 'DELETE ?' 7: 8: /*Enable Constraints & Triggers again*/ 9: exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL' 10: exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL' 11: 12: /*Reset Identity on tables with identity column*/ 13: exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
When you create tables in SQLServer (2005) by default its all get created under default schema. (dbo.)
If you have too many tables then the table list could be confusing / clumsy.
Here enters Schema
To organize your tables into meaningful groups (or namespaces)
First create a schema
CREATE SCHEMA Person
Then Alter your existing table
ALTER SCHEMA Lookup
So now that you have grouped your tables into different schemas.
How to use them ? The usual way but with schema name added to it.
SELECT * FROM Person.Contact
What is Schema ? (from MSDN)Beginning in SQL Server 2005, each object belongs to a database schema. A database schema is a distinct namespace that is separate from a
database user. Schemas can be created and altered in a database, and users can be granted access to a schema. A schema can be owned by any
user, and schema ownership is transferable.
In previous versions of SQL Server, database users and schemas were conceptually the same object. Beginning in SQL Server 2005, users and schemas
are separate, and schemas serve as containers of objects.
Prevent Session Timeout in Asp.net [VB]
ASP.Net 2.0 [VB]
I slightly modified few things to work for VB and VS2005 environment. The code works perfect and I’m very happy with it.First I created a Module file and created this function.
– Subtract 30 seconds from it and assign it to MilliSecondsTimeOut variable
– Create a global variable with max value 6
– Get current hour and Min [just for displaying the last refresh time]
– Verify whether count is less than max value (ie 6)
– If so, change the window status with Text
– Create a dummy image and set reconnect.aspx url as its source [this way a call is made to server and it wont session timeout]Create a timer using window.setInterval and assign the MilliSecondsTimeOut value.
[this way this function is called 30 seconds before session timeout]Tha max value (6) can be set to any number. If its 6 then this session timeout is avoided 5 times.
Default session timeout is 20min. 20 * 5 = 100 mins. Which is good for non-secure page.
On the pages where I want to prevent Session Timeout I entered this line.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try 'dont forget to add this line Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "reconn key", KeepAlive()) If Not Page.IsPostBack Then --- --- --- End If Catch eX as Exception '---- End Try End Sub
Created reconnect.aspx in Visual Studio and deleted the .vb and .designer.vb files.This is the final version of reconnect.aspx
<%@ Page Language="vb" AutoEventWireup="false"%> <%@ OutputCache Location="None" VaryByParam="None" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" mce_href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <html xmlns="<a href="http://www.w3.org/1999/xhtml" mce_href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>" > </html>
Note : When you compile the project sometimes, VS2005 complains reconnect.aspx is not in right format.
So I EXCLUDED this file from my project. Now VS 2005 will compile without complaining and the logic will also work.- Happy Programming
Few thoughts on how to enforce strong userids and passwords.
UserIDs can be email address. (An email can be sent to the ID with a link to make sure email id is valid)
– Password must be between 8 and 14 characters.
– Password must contain at least one number, at least one English uppercase character, and at least one English lowercase character.
– Password must contain one special character like #,*,&
– Password may not have more than two consecutive identical characters.
Ex : This is valid : grEen12# but grEEEn12# is not valid
– Password cannot be the same as your previous three passwords.
– Password cannot be similar as your previous three passwords.
Ex : If this is your old password grEen12#, new Password cannot be grEen13#
– Password cannot be the same as or contain your User ID or contain the word “password” or contain your site / company name.
Ex : If your site is abcjewellers then password cannot be aBcJewellers#1 or paSSword$1
– Password should expire every 60 days.
Inspired by ASP.NET 2.0 Server Side Comments
If you want to comment a particular column in GridView, HTML commenting approach wont work.
You have to use
<asp:GridView ID="gvSample" runat="server" AutoGenerateColumns="False" GridLines="None" CellPadding="0" CellSpacing="0"> <Columns> <asp:BoundField DataField="Column1"Â ItemStyle-Width="25px" /> <asp:BoundField DataField="Column2" ItemStyle-Width="15px" /> <asp:BoundField DataField="Column3" ItemStyle-Width="15px" /> <%-- Commented Column --%> <%-- <asp:BoundField DataField="Column4" ItemStyle-Width="15px" />--%> </Columns> </asp:GridView>