Friday, November 03, 2006

How to find database connection strings

When ever we create an application which has to be connected to a database, it needs a connection string. We all know the connection strings for widely used databases like SQL Server, MS Access, Oracle. If not we will find it in web. Then, how to find connection strings for less popular or rarely used databases. Yes you can.

Step 1: Open a notepad application
Step 2: Save the empty file with any name with udl extension (*.udl). Type the filename with extension with in quotes. Step 3: Double click the saved file.
Step 4: It will have 4 tabs (Provider, Connection, Advanced, All). Select "Provider" tab
Step 5: Select the provider. (To connect a database we need a driver or provider. If it is installed in the machine, it will be displayed in the Provider tab) and click Next. For Ex: Microsoft OLE DB for SQL Server
Step 6: Fill the appropriate information in the Connection tab, such as server name, username, password, database. Check the "Allow saving password" option. After filling the information click "Test Connection". It should pop up with the information"Test Connection succeeded".
Step 7: Click "Ok" to close the window. Click "Yes" for the next dialog.
Step 8: Now open the file in notepad. You will get the connection string.

Wednesday, November 01, 2006

When to use SQL Server Cursor

We mostly use Cursors when there is a need for row by row operation, which cannot by replaced by a nested queries. The greatest disadvantage in Cursors is it stores the result set in an memory and processes one by one. Suppose for 1000,00 records it occupies huge memory and performance is will very poor. In those cases it is always better to go for While Loop instead of a cursor. This improves the performance drastically.

declare @loopvar int
declare @maxcnt int
declare @cnter int
declare @outermax int
create table #temptable (

ROWID INT IDENTITY(1,1),
productgp int )

Insert into #temptableselect distinct id from products where status = 1 order by ID
set @outermax = @@ROWCOUNT

set @cnter = 1
While (@cnter <= @outermax)
Begin
// Do your process here

// Do your process here
set @cnter = @cnter +1
end

Use Cursors only if resultset is less in number, say less than 5000 records.

Monday, July 24, 2006

Remove Auto Complete

When ever we visit a site and enter anything in some textbox ex: Search keywords or username. It will appear at below at the nexttime you visit. How to stop this...

Just Add AutoComplete = false in form tag or that particular control.

Tuesday, June 27, 2006

Microsoft's Code sharing site

Microsoft has launched Code sharing site called www.codeplex.com
It has lot of source code with shared souce code licenses.
Popular products already available on the site include Microsoft's Atlas AJAX development tool kit and Iron Python beta 1

Make use of it.

Friday, June 23, 2006

Tuesday, June 20, 2006

Chip breaks speed record in deep freeze

What is your PC clock speed?

(800 MHz, 1 GHz, 1.8 GHz , 2.4 GHz, 2.6 GHz, 3 GHz Dualcore, 3.6 GHz)?

If your find the answer in the above line then, it shows you have a Grand old PC

Research has gone to such an extent, and created a chip with clock speed of 350 GHz at room temperature.
It is also possible to have a chip with a clock speed of 1THz (@ - 459 F or 0 K or -273 C ) when liquid helium is used for cooling.
It is made up of (SiGe). Silicon and Germanium, it is manufactured by IBM and Georgia Tech.


For more Information: http://news.zdnet.com/2100-9584-6085568.html

Now imagine how fast your windows will boot and how fast you can do CTRL+C CTRL+V?

AIM: To write a program that can run in watches, remote controls

All these time, we know using Microsoft technologies we can write applications that can run in PC, PDA, windows mobile, etc. Have you ever thought of writing application for watches, remote controls, cameras, and devices having very less memory, inexpensive processor and very less power?

Yes, Microsoft has done it.
.Net Framework for Usual applications
.Net Compact Framework for PDA and windows mobile (smart phones)
.Net Micro Framework for watches and remote controls.
At present MSN Direct Smart Watch works in .Net Micro Framework platform.


For more information:
http://www.aboutnetmf.com/entry.asp

Is it possible in Java technologies?

Sunday, June 18, 2006

Tracking file download

We usually put a hyperlink to download a file. But the following code helps to track the download. We can check whether the user has successfully downloaded the file or not. This can be used in juke box or movie download sites to prevent multiple downloads.

private void DownloadFile(string strfile)
{
System.IO.Stream iStream = null;
byte[] buffer = new Byte[1000];
int length;
long dataToRead=-1;

bool startstatus=false;
string filepath = strfile;
string filename = System.IO.Path.GetFileName(filepath);

try
{
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,System.IO.FileAccess.Read, System.IO.FileShare.Read);
dataToRead = iStream.Length;

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

while (dataToRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read the data in buffer.
length = iStream.Read(buffer, 0, 1000);

// Write the data to the current output
Response.OutputStream.Write(buffer, 0, length);

// Flush the data to the HTML output.
Response.Flush();
buffer= new Byte[1000];
dataToRead = dataToRead - length;

if(startstatus == false)
{
// Started downloading

startstatus=true;
}

}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
// disconnected or unable to download
}
}
}
catch (Exception ex)
{
dataToRead = -1;
}
finally
{
try
{
if(dataToRead == -1)
{
// disconnected or unable to download
}
else
{
// file successfully downloaded
}
if (iStream != null)
{
//Close the file.
iStream.Close();
}
}
catch(Exception ex)
{

}
}
}

Tuesday, June 06, 2006

Enterprise Library - June 2005

We daily write application but it is better to follow best practices and patterns developed by Microsoft. They have released a enterprise library which includes
Caching ApplicationBlock

Configuration Application Block
Data Access Application Block
Cryptography Application Block
Exception Handling Application Block
Logging and Instrumentation Application Block
Security Application Block

The following are the links for learning Enterprise library.
Download Enterprise library

Learning materials

Thursday, May 11, 2006

Windows Sharepoint Service - 3

In continuation with previous post. Now we will see how to create a individual WSS farm and a child site

Create a new IIS Web Site
a. Open IIS Manager
b. Right-Click on Webs Sites, New -> Web Site to open the Web Site Wizard
c. Enter a description of WSS and click Next
d. Leave IP Address and Port unchanged, but enter WSS in the Host Headers field and click Next
** This assumes you have a DNS record for WSS and the server IP
e. Click Browse then create a new folder under c:\inetpub called WSS and select it, then click Next
f. On the screen title Web Site Access Permissions click Next
g. Click Finish to complete the Web Site creation
Extend the new IIS Web Site
By extending a virtual server we are effectively installing WSS onto the Web Site.
a. Open SharePoint Central Administration - Start -> Administrative Tools -> SharePoint Central Administration
b. Ensure Windows SharePoint Services administration is displayed, link in left column
c. Click on Configure Virtual Server Settings
d. Click on the WSS link
e. On the Extend Virtual Server page, click on Extend and create a content database
f. On the Extend and create content database page, select Use an existing application pool, and choose MSSharePointAppPool from the dropdown.
** Additional Application Pools can be configured to separate instances of WSS running on a single server and thereby ensuring a fault in one application does not affect another.
g. Enter and email address, for example
administrator@localhost and click OK
** Extending the virtual server may take some time
h. When completed click on
http://wss/
i. When asked to select a template, chose whichever one suits, for example Team Site

Your new dedicated WSS Team Site farm as now been created, all that is needed it to connect it to the Portal

Configure the Portal to use the new Team Site Farm
Once the new WSS environment has been created, Self Service Site Creation must be enabled and the Portal used to create and manage the team sites needs to be informed of the location of the new environment.

a. Open SharePoint Central Administration - Start -> Administrative Tools -> SharePoint Central Administration
b. Click on the Configure Virtual Server Settings link
c. Click on the WSS link
d. Click on Configure Self-Service Site Creation
e. Ensure the option is set to On and then click OK
f. Open the Portal by browsing to
http://portal/
g. Click on the Site Settings link
h. Click on the Change portal site properties and SharePoint site creation settings link
i. In the Location for Creating SharePoint Sites field enter:
http://WSS/_layouts/1033/scsignup.aspx
And click OK

Create a new Team Site
With the portal now configured to use the new dedicated Team Site environment, we can create a new Team Site.

a. Click on the Sites link
b. Click on the Create Site link
c. Enter a Title (eg. Demo Site), URL and Owner for the site and click OK
d. On the Add Link to Site screen, which adds the new site to the Site Registry, leave as default and click on OK
e. Select a Template and click OK
f. Verify that your new Team Site has been successfully created on the WSS virtual server

This is how you create a website and a child site.
There are five site groups in WSS

Guest - By default nothing
Reader - Use Self-Service Site Creation, View Pages, View Items,
Contributor - All rights included in the Reader site group, plus:Add Items, Add/Remove Private Web Parts, Browse Directories. Create Cross-Site Groups, Delete Items, Edit Items, Manage Personal Views, Update Personal Web Parts
Web Designer - All rights included in the Contributor site group, plus: Add and Customize Pages, Apply Themes and Borders, Apply Style Sheets, Cancel Check-out, Manage Lists
Administrator - All rights included in the Web Designer site group, plus: Create Subsites, Manage List Permissions, Manage Site Groups, View Usage DataData

For more information download administrator's userguidehttp://www.microsoft.com/downloads/details.aspx?FamilyID=a637eff6-8224-4b19-a6a4-3e33fa13d230&DisplayLang=en

Windows Sharepoint Service - 2

In continuation with previous post. Now we will see how to install Windows Sharepoint Service (WSS). This is a free version of Sharepoint portal server.
First we need the installer file. Here you downlaad the installer http://www.microsoft.com/windowsserver2003/technologies/sharepoint/default.mspx
It is just 34 MB


Check whether your machine meet the requirements
Windows 2003
.Net 1.1
IIS 6.0
Sql server 2000/MSDE


Double click on the downloded file STSV2.EXE.
This will cause Windows to decompress the file’s contents and to launch the installation program.
1. The Setup wizard appears, accept the license agreement and click Next to continue.
2. The next screen will ask you if you would like to perform a typical installation or if you would rather set up a server farm.
select the Typical Installation option and click Next.
3. The Setup program will now confirm that it is about to install the SharePoint Services and that the target drive has enough free space. Click the Install button to begin installing the necessary files.
4. As the installation progresses, you might notice a message indicating that Setup is configuring the Microsoft SQL Desktop Engine. The Windows SharePoint Services are dependant on SQL Server. As we all know though, SQL Server can be expensive. If you don’t have SQL Server installed on your server prior to installing the Windows SharePoint Services, Setup will automatically configure the SharePoint Services to use MSDE.


Once you the installtion is complete. Go to control panel>> administrative tools you will see the link to sharepoint adminstration. On double clicking you will see a page where you can create websites in sharepoint portal server and configuring them.

Tuesday, May 02, 2006

How are bit columns stored by the SQL Server?

How are bit columns stored by the SQL Server storage engine?

1. Each field is stored as an 8-bit integer.
2. All bit columns are stored together in 8-bit(byte) groups.

3. Bit columns are stored the same as varbinary columns.
4. All bit columns are stored together in two contiguous bytes since SQL Server only allows 16 bit columns in a row. 5. Each bit column is stored in its respective place in the row as a single bit.


Answer:
2. Microsoft® SQL Server™ optimizes the storage used for bit columns. If there are 8 or fewer bit columns in a table, the columns are stored as 1 byte. If there are from 9 through 16 bit columns, they are stored as 2 bytes, and so on.

Thursday, April 27, 2006

Windows Sharepoint Service - 1

Why we need a sharpened?
All these time we have traditional ways of sharing information through meetings, docs, assigning task, maintaining contacts, lists, lots of things, version controlling, and many more. Most of the things are available in content management systems. For version controlling we can go for some free tools like CVS and Microsoft Visual Sourcesafe. How to get everything in integrated. How to create sites and share information without programming knowledge. Yes everything is possible if you are ready click Next, Next , ....button (All are wizard). All the above the interfaces is in web. You can administer the site from anywhere in the network.


What is the history behind Sharepoint?
Initially it was started as Sharepoint team services - > STS in 2001
It was based on IIS arch. It was a stateful server. Very difficult to maintain web farm.
Customization was difficult. It was using ISAPI extensions and it was developed in ASP

What are the highlights of sharepoint?
Document sharing
Versioning
Web URL
Administration
Area, Topics
Personal sites
Audiences
SSO (single sign on)
Site search
Integration with biztalk
Indexing...... and many more


Is it licensed?
The basic version is absolutely free and it is just 34MB (Windows Sharepoint services) WSS. About 60% of SPS is made free through this.
and Sharepoint Portal service is a licensed.

What are the requirements?
Windows 2003
IIS 6
.Net 1.1
MSDE / Sql server


Tuesday, April 25, 2006

Hit a server side page through XMLHTTP...

Wanna hit a server side page without submitting the main page…

function DoCallback(url, params)//GENERAL FUNCTION...

{

var pageUrl = url + "? + params;

var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");

xmlRequest.open("POST", pageUrl, false);

xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xmlRequest.send(null);

return xmlRequest;

}

Usage of the abovesaid function…

var xmlRequest = DoCallback("ClinicalDocument.aspx", "AddFavor=true”);

var resText = xmlRequest.responseText;

this function with hit the server side page… without postback of the main page…

try it out…

Thursday, February 16, 2006

Oracle from unbreakable to unpatchable

Once upon a time Oracle was unbreakable but now it was broken several times and unable to plug the hole. Oracle PL/SQL Gateway, which allows a hacker to gain full administrative control of a back-end database from anywhere on the Internet. This is yet to get a patched and will be fixed in next quarter with fixes for 82 critical vulnerabilities all its products.
All because most people are not used to it does not mean you can claim it is unbreakable.


Courtesy: http://blogs.zdnet.com/Ou/?p=151&tag=nl.e622

Microsoft Office Live

Microsoft Live is now in Beta. In Beta everything is free. This includes own domain name, five email accounts 2 GB each, web traffic report, and website storage size of 30MB.

Dont wait click the following link http://officelive.microsoft.com/

Sunday, February 05, 2006

Aspnet_wp.exe could not be started

Last week I had a problem, When I moved to new machine. I was able install everything except ASP.NET, Then I checked the status of Aspnet_wp.exe, it was not running. I re-installed whole asp.net using aspnet_regiis.exe. I was bored and started searching. Then i found, it was due to security in related folders.


WORKAROUND
To work around this problem, verify that the ASPNET account has the correct user rights as follows:

• %windir%\Microsoft.NET\Framework\Version\Temporary ASP.NET Files: Full Control
• %windir%\Temp: Full Control
• Application folder: Read
• %installroot% hierarchy (for example, %windir%\Microsoft.Net\Framework\Version): Read
• %windir%\Assembly: Read

Note This is the global assembly cache. You cannot directly use Windows Explorer to edit ACLs for this folder. Instead, open a command window, and then run the following command:

cacls %windir%\assembly /e /t /p domain\useraccount:RAlternatively, before you use Windows Explorer, run the following command to unregister Shfusion.dll:
regsvr32–u shfusion.dll

After you set user rights in Windows Explorer, run the following command to re-register Shfusion.dll:
regsvr32 shfusion.dll

• Web site root (for example, %root%\Inetpub\Wwwroot) or the path that the default Web site points to: Read

• %windir%\System32: Read (Typically, the ASPNET account has already been granted user rights as a member of the Users group.)


Courtesy : http://support.microsoft.com/default.aspx?kbid=811320

How to remove duplicate rows from a table in SQL Server

How to remove duplicate rows from a table in SQL ServerWe sometime get into a situation, where we have to remove dulicate records from a given table. It is atedious process if we remove one by one. The following article will help you to remove duplicate records from a table

SUMMARY

Microsoft SQL Server tables should never contain duplicate rows, nor non-unique primary keys. For brevity, we will sometimes refer to primary keys as "key" or "PK" in this article, but this will always denote "primary key." Duplicate PKs are a violation of entity integrity, and should be disallowed in a relational system. SQL Server has various mechanisms for enforcing entity integrity, including indexes, UNIQUE constraints, PRIMARY KEY constraints, and triggers. Despite this, under unusual circumstances duplicate primary keys may occur, and if so they must be eliminated. One way they can occur is if duplicate PKs exist in non-relational data outside SQL Server, and the data is imported while PK uniqueness is not being enforced. Another way they can occur is through a database design error, such as not enforcing entity integrity on each table. Often duplicate PKs are noticed when you attempt to create a unique index, which will abort if duplicate keys are found.

This message is:
Msg 1505, Level 16, State 1 Create unique index aborted on duplicate key. If you are using SQL Server 2000 or SQL Server 2005, you may receive the following error message:

Msg 1505, Level 16, State 1 CREATE UNIQUE INDEX terminated because a duplicate key was found for object name '%.*ls' and index name '%.*ls'. The duplicate key value is %ls. This article discusses how to locate and remove duplicate primary keys from a table. However, you should closely examine the process which allowed the duplicates to happen in order to prevent a recurrence.

MORE INFORMATION
For this example, we will use the following table with duplicate PK values. In this table the primary key is the two columns (col1, col2). We cannot create a unique index or PRIMARY KEY constraint since two rows have duplicate PKs. This procedure illustrates how to identify and remove the duplicates.

create table t1(col1 int, col2 int, col3 char(50))insert into t1 values (1, 1, 'data value one')insert into t1 values (1, 1, 'data value one')insert into t1 values (1, 2, 'data value two')
The first step is to identify which rows have duplicate primary key values: SELECT col1, col2, count(*)FROM t1GROUP BY col1, col2HAVING count(*) < 1

This will return one row for each set of duplicate PK values in the table. The last column in this result is the number of duplicates for the particular PK value.
col1 col2
1 1 2
If there are only a few sets of duplicate PK values, the best procedure is to delete these manually on an individual basis. For example:

set rowcount 1delete from t1where col1=1 and col2=1
The rowcount value should be n-1 the number of duplicates for a given key value. In this example, there are 2 duplicates so rowcount is set to 1. The col1/col2 values are taken from the above GROUP BY query result. If the GROUP BY query returns multiple rows, the "set rowcount" query will have to be run once for each of these rows. Each time it is run, set rowcount to n-1 the number of duplicates of the particular PK value.

Before deleting the rows, you should verify that the entire row is duplicate. While unlikely, it is possible that the PK values are duplicate, yet the row as a whole is not. An example of this would be a table with Social Security Number as the primary key, and having two different people (or rows) with the same number, each having unique attributes. In such a case whatever malfunction caused the duplicate key may have also caused valid unique data to be placed in the row. This data should copied out and preserved for study and possible reconciliation prior to deleting the data.

If there are many distinct sets of duplicate PK values in the table, it may be too time-consuming to remove them individually. In this case the following procedure can be used:

1. First, run the above GROUP BY query to determine how many sets of duplicate PK values exist, and the count of duplicates for each set.

2. Select the duplicate key values into a holding table.
For example:SELECT col1, col2, col3=count(*)INTO holdkeyFROM t1GROUP BY col1, col2HAVING count(*) > 1

3. Select the duplicate rows into a holding table, eliminating duplicates in the process. For example:SELECT DISTINCT t1.*INTO holddupsFROM t1, holdkeyWHERE t1.col1 = holdkey.col1AND t1.col2 = holdkey.col2

4. At this point, the holddups table should have unique PKs, however, this will not be the case if t1 had duplicate PKs, yet unique rows (as in the SSN example above). Verify that each key in holddups is unique, and that you do not have duplicate keys, yet unique rows. If so, you must stop here and reconcile which of the rows you wish to keep for a given duplicate key value. For example, the query: S
ELECT col1, col2, count(*)FROM holddupsGROUP BY col1, col2

should return a count of 1 for each row. If yes, proceed to step 5 below. If no, you have duplicate keys, yet unique rows, and need to decide which rows to save. This will usually entail either discarding a row, or creating a new unique key value for this row. Take one of these two steps for each such duplicate PK in the holddups table.

5. Delete the duplicate rows from the original table.
For example:DELETE t1FROM t1, holdkeyWHERE t1.col1 = holdkey.col1AND t1.col2 = holdkey.col2 6. Put the unique rows back in the original table.
For example:INSERT t1 SELECT * FROM holddups

Courtesy::
http://support.microsoft.com/default.aspx?scid=kb;en-us;139444

Wednesday, February 01, 2006

Convert Julian Date to System.DateTime

Yesterday I had a requirement for converting Julian date to normal date and compare the date with a given date. I searched many times and I got Julian calendar and I didn't get any date conversion in .NET. But I got many examples in JavaScript how to convert Julian date to mm/dd/yyyy. I just converted JavaScript code to C#. Hope this helps to all you.


private DateTime ConvertJulianToDateTime(double julianDate)
{
DateTime date;
double dblA, dblB, dblC, dblD, dblE, dblF;
double dblZ, dblW, dblX;
int day, month, year;
try
{
dblZ = Math.Floor(julianDate + 0.5);
dblW = Math.Floor((dblZ - 1867216.25) / 36524.25);
dblX = Math.Floor(dblW / 4);
dblA = dblZ + 1 + dblW - dblX;
dblB = dblA + 1524;
dblC = Math.Floor((dblB - 122.1) / 365.25);
dblD = Math.Floor(365.25 * dblC);
dblE = Math.Floor((dblB - dblD) / 30.6001);
dblF = Math.Floor(30.6001 * dblE);
day = Convert.ToInt32(dblB - dblD - dblF);
if (dblE > 13)
{
month = Convert.ToInt32(dblE - 13);
}
else
{
month = Convert.ToInt32(dblE - 1);
}
if ((month == 1) (month == 2))
{
year = Convert.ToInt32(dblC - 4715);
}
else
{
year = Convert.ToInt32(dblC - 4716);
}
date = new DateTime(year, month, day);
return date;
}
catch (ArgumentOutOfRangeException ex)
{
MessageBox.Show("Julian date could not be converted:\n" + ex.Message, "Conversion Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
date = new DateTime(0);
}
catch (Exception ex)
{
MessageBox.Show("Error converting Julian date:\n" +
ex.Message, "Conversion Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
date = new DateTime(0);
}
return date;
}



To learn more about about Julian dates, visit http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html

Saturday, January 07, 2006

Alternate to PDF

Most of the time our client wants report to be light weight and easily opened. If we use PDF, it needs Abode Reader to open PDF documents. So to over come this problem, here is the solution, MHTML. MHTML files store images and text in single file as MS Word does. To Open MHTML files, you need Internet explorer or MS Word 2000 and above.

How to create MHTML?
Easy, Just pass the URL to this method


public static bool SaveWebPageToMHTFile( string url, string filePath)
{
bool result=false;
CDO.Message msg = new CDO.MessageClass();
ADODB.Stream stm=null ;
try
{
msg.MimeFormatted =true;
msg.CreateMHTMLBody(url,CDO.CdoMHTMLFlags.cdoSuppressNone, "" ,"" );
stm = msg.GetStream();
stm.SaveToFile(filePath,ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
msg=null;
stm.Close();
result=true;
}
catch
{throw;}
finally
{
//cleanup here
}return result

Sunday, January 01, 2006

Free Modeling tool

Gentleware has come up with a Free Modeling tool called poseidon. The comunity edition is free downloadable and with full functionality. It needs JRE 1.4 or higher. As it is developed in Java it is platform independent.

For more information:
www.gentleware.com