Archive for the ‘Tips and Tricks’ Category
Disable .pdb file generation in Release Mode
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.
SQL Server 2005 : Access Tables / Entities across Servers.
Accessing objects (tables..) across servers (SQL Server) is very simple.
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
PRODSVR.dbname.dbo.tablename
To access Person.Address table from AdventureWorks database
Select * From PRODSVR.AdventureWorks.Person.Address
Advantages :
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)
SQL Server, Clean your Database Records and reset Identity Columns, The Shortest Path
(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'
Organize your SQL Server 2005 tables in a better way !!
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
(see image)
To organize your tables into meaningful groups (or namespaces)
First create a schema
CREATE SCHEMA Person
GO
Then Alter your existing table
ALTER SCHEMA Lookup
TRANSFER dbo.Contact
GO
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
Prevent Session Timeout in Asp.net [VB]
ASP.Net 2.0 [VB]
Inspired by this article from Code Project. [Thanks Ach1lles ]
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.
Public Function KeepAlive() As String Dim int_MilliSecondsTimeOut As Integer = (HttpContext.Current.Session.Timeout * 60000) - 30000 Dim sScript As New StringBuilder sScript.Append("<script type='text/javascript'>" & vbNewLine) 'Number Of Reconnects sScript.Append("var count=0;" & vbNewLine) 'Maximum reconnects Setting sScript.Append("var max = 6;" & vbNewLine) sScript.Append("function Reconnect(){" & vbNewLine) sScript.Append("count++;" & vbNewLine) sScript.Append("var d = new Date();" & vbNewLine) sScript.Append("var curr_hour = d.getHours();" & vbNewLine) sScript.Append("var curr_min = d.getMinutes();" & vbNewLine) sScript.Append("if (count < max){" & vbNewLine) sScript.Append("window.status = 'Refreshed ' + count.toString() + ' time(s) [' + curr_hour + ':' + curr_min + ']';" & vbNewLine) sScript.Append("var img = new Image(1,1);" & vbNewLine) sScript.Append("img.src = 'http://localhost/myapp/reconnect.aspx';" & vbNewLine) sScript.Append("}" & vbNewLine) sScript.Append("}" & vbNewLine) sScript.Append("window.setInterval('Reconnect()',") sScript.Append(int_MilliSecondsTimeOut.ToString() & "); //Set to length required" & vbNewLine) sScript.Append("</script>") KeepAlive = sScript.ToString End Function
All this code does is, build a simple javascript function and its called from server side.The works like this,- Gets the current session timeout duration.
– Subtract 30 seconds from it and assign it to MilliSecondsTimeOut variable
– Create a Reconnect() javascript function
– 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.
Then
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
How strong User ID and Password should be ?
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.
Vista seems to be slower ?
With all the dual core processors and 1+ GB RAM Microsoft VISTA didn’t perform as expected.
Later I found out the default power setting in the “Power Saver” plan limits the CPU to 50 percent.
To improve the speed
Open the Power Options from Control panel and change it to “High Performance” to give it full throttle.
Create/Manage Multiple Websites in IIS on Windows 2000 / XP
On Windows 2000/XP Professional only one website can be created in IIS. (i.e) default website.
If you have some requirement for testing multiple websites on same development box its not possible with IIS alone.
FREE IIS Management tool
JetStat has a tool to accomplish the above mentioned task. “IISAdmin”
It has some cool features like
– Create and Manage as many local IIS web sites.
– Install and configure asp scripts on local web sites
– Gives quick access to home folder of the website
– Enabling advanced features on creation of new web site
– Quick access to IIS Management Console
– Automatically configures database folder permissions
– Full support Windows 2000/XP (IIS 5.0, 5.1, 6.0)
– Easy of use and flexible
The application is FREE and it doesn’t occupy much space.
Download from here.
XP to Vista migration.
If you are a developer / power user who uses 2000 / XP professional you need to upgrade to Vista Ultimate.
Even though Vista Home Premium has IIS it doesn’t support (or features enabled) in home premium edition.
For ex: If you want to see Local User Groups (Admin tools, Comp mgt) you can not see that in Home Premium. Its available in Ultimate edition.
Steps to Change from Visual Studio Development Server to Use IIS Web Server
Using Visual Studio 2005
1. Goto Project Properties > Select Web Tab
2. Click “Use IIS Web Server” radio button
3. Click on “Create Virtual Directory” button
4. Open Web.config and change debug to true <compilation debug=”true”>
5. Open IIS (Start > Run > Inetmgr)
6. Goto that your project Virtual Directory
7. Right click > Select Properties
8. Under Virutal Directory Tab, make sure it has Application Name. If its blank, click on Remove button next to it and click Create.
9. Under ASP.Net tab make sure Asp.net Version is 2.0 or whatever you need
10. Under Directory Security tab click EDIT
11. Make sure Anonymous and Integrated Windows authentication is enabled.
If these steps are not followed
you may not be able to debug you application using Visual Studio,
you may not be able to use IIS web server or its features.
Developers PC – What should it have ? How it should be ?
These are the optimized settings I found and use for my PC running with xp & vista. (You have the right to disagree with me 100%)
– Switch start menu to classic mode. No jazzy menus, so no delay in loading menu .
– Keep desktop background plain and simple. I prefer using black background so that the icons stand out.
– Enable Quick Launch in taskbar.
– Add NOTEPAD & frequently used application shortcuts in quick launch.
– Pay attention to Windows Update & Windows defender scanning. If it prompts update it. Its good practice to keep your system smooth. (Unless you have restriction not to update)
BROWSER Setting
– My work expects me to use IE (which is great ofcourse), keep blank page as startup page.
– Customize the icons and remove the unwanted ones like EDIT, PRINT, MAIL and so on.
– Keep small icons instead of Large icons.
– Organize your favourites menu. Create folders and sub folders under LINKS and move frequently used items under it. It helps me a lot.
– Install Google Toolbar. It helps in better search. Once you start typing, it prompts with previously done searches. (I love this feature)
– Uninstall any unwanted toolbars (i hate the bulky Yahoo & MSN toolbars).
What can you do to improve your efficiency ?
Use both your hands (not just index finger) while typing and selecting menus.
Use mouse to the minimum. (unless you are using some graphical software or doing some audio/video editing)
Use shortcuts as much as you can. (click here to see list of windows shortcuts)
(more to come..)
Stop the Search (Visual Studio 2003)
Search on all folders
When using Visual Studio, there are times you need to search entire project or solution.
The short cut for this search is CTRL + Shift + F
Stop the Search
If you are lucky enough, the page you are looking for will appear first. If you want to STOP rest of the search
press CTRL + Shift + F again.
It will show the STOP button instead of SEARCH button.
Click STOP.
Recordset to Datatable (Asp.Net)
If you are migrating your application from Asp to Asp.Net, Recordsets to Datatable will be key issue.
If you want to utilize the power of Datagrid or any Asp.net controls then DataTable and DataSets is the way to go.
Fortunately converting Recordset to DataTable or DataSet is very easy.
Steps
1 . Create an OleDb DataAdapter
2. Create a DataTable Object
3. Fill the Adapter with Recordset values.
4. Add DataTable to DataSet (if needed)
Now the coding part
Dim MyAdapter As OleDbDataAdapter = New OleDbDataAdapter() Dim <strong>dtRSTable</strong> As System.Data.DataTable = New DataTable() MyAdapter.Fill(<strong>dtRSTable</strong>, Rs) Now <strong>dtRSTable</strong> is ready. This dtRSTable can be directly referenced in a datagrid or added to DataSet dgSampleGrid.datasource = dtRSTable.Defaultview dgSampleGrid.databind 'or 'Adding DataTable to DataSet dim dsTable as New DataSet dsTable.Tables.Add(dtRSTable)
View Negative Images Instantly
Some websites publish negative images to hide the actual identity. Creating negative image can be easily done using Adobe Photoshop.
Open an Image and Press CTRL + I, save the image.
To reveal
the actual picture do the same. CTRL + I acts as toggle
switch
Recently i found out you dont even need to have photoshop.
Open Microsoft WORD, Insert the picture and press CTRL + A (Select All)
tadaa…
Deleting MRU Entries (Office)
The MRU refers to “most recently used,” which is the list of files you have used recently, as noted at the bottom of the File menu. This list is a wonderful aid most of the time, but is also very revealing. Everyone who uses your computer knows the name of the last file (or files) you’ve been working on.
You may not always like this.
- To remove a file name from the MRU list, press ALT+CTRL+- (that last part is a dash, right next to the 0 key).
- The mouse pointer changes into a thick bar.
- Use the bar pointer to click on the File menu, then click on the MRU entry you wish to remove from the list.
- The entry is removed, and the mouse pointer changes back to normal.
Note :
This does not delete the actual file; it only removes the entry from the MRU list.
Comment on Server Side Asp.Net
with 2 comments
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
example:
Written by gchandra
October 2, 2007 at 9:53 am
Posted in Asp.Net, Tips and Tricks
Tagged with Asp.Net, Commenting, ServerSideControl