Wednesday, December 8, 2010

How to check weather a username exists on a domain comtroller?.

The below code will help you to check wether a specified user exists on the domain controlller or not.


bool AdsVlaid = false;

string username = "it";

string domain="server";

string path = String.Format("WinNT://{0}/{1},user", domain, username);

try

{

DirectoryEntry.Exists(path);

AdsVlaid= true;

}

catch (Exception ex)

{

AdsVlaid = false;

MessageBox.Show(ex.Message);

// For WinNT provider DirectoryEntry.Exists throws an exception

// instead of returning false so we need to trap it.

}

For more infomation please visit the below links

http://www.codeproject.com/KB/system/everythingInAD.aspx

http://stackoverflow.com/questions/1329833/how-to-check-if-windows-user-account-name-exists-in-domain

How to check the User credential of a user with a domain controller?

The below code will help you to check the username and password of a user on a domain controller


System.DirectoryServices.AccountManagement.PrincipalContext PrincipalContext = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, "server");

bool AdsVlaid = PrincipalContext.ValidateCredentials("it", "13@mf3-25");

Tuesday, December 7, 2010

How to Configure ReportViewer for Remote Processing in Windows and Asp .net?

To configure a ReportViewer control for remote processing, specify a server report to use with the control. Follow these steps to select a server report:


1. Add the ReportViewer control from the Data section of the Toolbox to the form or Web page in your project.

2. In the ReportViewer Tasks smart tags panel, in Choose Report, select Server Report.

3. In the Report Server text box, type the report server URL. The default URL syntax is http://localhost/reportserver. The actual URL that is used in your installation might be different depending on how the report server virtual directory settings are configured.

4. In the Report Path text box, type the fully qualified path of a published report. The report path must start with a forward slash ( / ). The path must not include report URL parameters. The path consists of folders in the report server folder namespace and the name of the report. For example, if you installed the SQL Server 2005 sample report Company Sales on your report server, the report path might be /AdventureWorks Sample Reports/Company Sales.

5. Build or deploy the application to verify that the report appears correctly in your application. If you receive HTTP proxy errors, verify that the report server URL is correct. If you receive a compatibility error, confirm that the report server is a SQL Server 2005 instance.

6. Select the ReportViewer control and open the Properties window.

7. Set properties on the ReportViewer control to configure the report toolbar and run-time functionality. Use the reference documentation to learn about each property. For more information, see ReportViewer Properties.

For More Details


http://msdn.microsoft.com/en-us/library/ms252075(v=VS.80).aspx

Thursday, November 18, 2010

How to store more than one value in a asp.net dropdown using attributes?

The below code will help you to store an additional value in the dropdown and access it using JavaScript, Using the below logic you can also store more value in different attributes in the same list.

Wednesday, October 27, 2010

How to use Lamda Expression in list.FindIndex() c# to find the index of a charater in chracter array?.

The below code will help you to find the index of a charatecte from the list or array


string[] alphabet = {"A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O","P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","1","2","3","4","5","6","7","8","9","0"};

int index= alphabet.ToList().FindIndex(s => s == "G");.

X will contain the index of the character G in the list or array.

You can find more infomration regarding lamda expression from the below link

http://msdn.microsoft.com/en-us/library/bb397687.aspx

How to split a string with more than one delimiter in c#?

The below code will help you to split a string with more than one charatesrs
string Formula = "((1200+2300)4000)";

char[] delimiters = new char[] { '(', ')','+','-','=' };

string[] AcountCodes;

AcountCodes =formula.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)

This issues happens when modifying document while it's being loaded (when browser hasn't "seen" closing tag for this element) . This causes very tricky situation in the parser and in IE it's not allowed For more explanation please vists the IE blog

http://blogs.msdn.com/b/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx

http://stackoverflow.com/questions/301484/problem-with-html-parser-in-ie

Thursday, October 14, 2010

How to covert an xml values to a table in SQL server 2005?

The below code will read xml data from a variable and will covert it to a temporary table.


Regards Rajesh Kamalakshan

Wednesday, October 13, 2010

How to attach a mdf file to a database in SQL server 2005?

You can use the below command to attach a mdf file to a database in SQL Server 2005.


sp_attach_single_file_db @dbname= 'adminv2', @physname= C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\adminv2.mdf'

Tuesday, July 13, 2010

How to know the number of rows in all the tables in a SQL server 2005 database?

The blow query will show the number of rows in all the tables in a SQL server 2005 database


select distinct sysobjects.name,sysindexes.rows from sysobjects
inner join sysindexes on sysindexes.id=sysobjects.id
where sysobjects.xtype='u'
order by sysindexes.rows desc

or you can use the below querry to the same details

SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count

FROM sys.dm_db_partition_stats st
WHERE index_id < 2
ORDER BY st.row_count DESC

Saturday, July 10, 2010

How to clear the text values of an Ajax ComboBox control?

Today I had Googled a lot to find a solution for clearing the text box values of an Ajax ComboBox, but unfortunately I could find any accurate solution. Then I finally decided to make some changes to the code which is published in my blog (http://rajeshkamalakshan.blogspot.com/2010/05/how-to-get-selected-text-of-microsoft.html) to achieve the above result.

For all you please find the code to clear the text box values of an Ajax ComboBox

Friday, June 4, 2010

How to insert mutlitiple rows into a table using insert and select statement?

Please find below how you can insert mutipe rows to a table by uing a select satement .
 for this example let us create a table as below

create table Batting (Player varchar(10), Year int, Team varchar(10), HomeRuns int, primary key(Player,Year))

The row to the above table can be inserted by uing the below sql querry.
 insert into Batting

select 'A',2001,'Red Sox',13 union all
select 'A',2002,'Red Sox',23 union all
select 'A',2003,'Red Sox',19 union all
select 'A',2004,'Red Sox',14 union all
select 'A',2005,'Red Sox',11 union all
select 'B',2001,'Yankees',42 union all
select 'B',2002,'Yankees',39 union all
select 'B',2003,'Yankees',42 union all
select 'B',2004,'Yankees',29 union all
select 'C',2002,'Yankees',2 union all
select 'C',2003,'Yankees',3 union all
select 'C',2004,'Red Sox',6 union all
select 'C',2005,'Red Sox',9

Friday, May 28, 2010

How to initiate a JavaScript function after an Ajax post back or Page load?

The below code will explain you how to call a function after an Ajax post back using Sys.Application.add_load.you can hook a fuction to this evvent with will be called after a page is loaded after ajax postback.
 

How to select an item in a dropdown (combobox) by its values using JavaScript?

You can select an item a by its values using the below code.


You can also get more information regarding various function and propertied of a dropdown (combobox) from the below link. http://www.navioo.com/javascript/dhtml/Changing_Select_Element_Content_two_Combobox_2755.html

How to get the selected values of dropdown (combobox) using JavaScript?

The selected values of a dropdown (combobox) can be accessed by the values and text property of a dropdown’s (combobox) option object.

The option object has the following properties.

defaultSelected          Refers to the option that is selected by
                                 default from the select box.

index                         Refers to the zero-based indexed location
                                of an element in the Select.options array.

selected                     Refers to the selected value of
                                 the select box.

text                            Refers to the text for the option.

value                          Refers to the value that is returned
                                  when the option is selected.

Accessing the value of a dropdown (combobox) is shown in the below example.


You can also get more information regarding various function and propertied of a dropdown (combobox) from the below link.
http://www.navioo.com/javascript/dhtml/Changing_Select_Element_Content_two_Combobox_2755.html

Thursday, May 27, 2010

Date Functions in Java Script?

To handle the date time function in javascript ,i sugesst to use the pre coded fucntion in the web site below.You can use the function in the below site free of cost in your code.

Thre are also other usefull javascript function in this site.

http://www.mattkruse.com/javascript/date/

Thursday, May 6, 2010

How to format a string in c# or how to use string.Format?

This String.Format method accepts a format string followed by one to many variables that are to be formatted. The format string consists of placeholders, which are essentially locations to place the value of the variables you pass into the function. These placeholders have the following format:


{indexNumber:formatCharacter}

The below code will convert 1 to 01
string.Format("{0:00}",1)

The Below code will convert a date to the format as "06/05/2010"
string.Format("{0:dd/MM/yyy}",DateTime.Now)

The Below code will convert a date to the formatas "Thursday, May 06, 2010"
string.Format("{0:D}", DateTime.Now)

The Below code will convert a date to the format as “Thursday”
string.Format("{0:dddd}", DateTime.Now)

The Below code will convert the number to currency as “"$1,234.00"”
string.Format("{0:c}", 1234)



You can find more into from the below link.
http://idunno.org/archive/2004/14/01/122.aspx

How to write conditional statement without using if key word in c# or How to use ternary operator?

The below code is a replacement of if keyword in c#  which you can accomplish by using the the conditional operator (?:)

condition ? first_expression : second_expression;

Ifyou excecute the below code it will print the value 20 .

int i = (2 > 3) ? 10 : 20;
Response.Write(i.ToString());

If we split the above code then (2 > 3) is considered as the condition, the result before : will be returned if the condition is true and the result after the : will be returned if it is false.

More Information can be out in the link below
http://msdn.microsoft.com/en-us/library/ty67wk28(VS.80).aspx

Wednesday, May 5, 2010

Have you used a condition like below in c#?


This above code will print false.
This staement can be further modified for function to return a boolen depending on the calculated values like below

The above function will also return return false if called like below.

Tuesday, May 4, 2010

How to hide a control using javascript in page_load or window.onload event?

The below code will help you to hide a control in page_laod event of javascipt.

How to get the selected text of a microsoft ajax combobox using javascript ?

The belwo example whill show you  how to get the selected text of a ajax combobox.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).


When I sued the above code in my aspx page I was getting the eroor as .

“The Controls collection cannot be modified because the control contains code blocks (i.e. ).”
This error can be solved by just replacing the code as below .

Other wise pass the control’s clientId as a parameter to the javascript function from thes server side code.

Replace your code as below will solve the issue.

You can also find other solution in the bleow link.
http://www.west-wind.com/weblog/posts/5758.aspx

Saturday, May 1, 2010

How to Create stored procedure or View in SQL 2005 with encryption?

You can encrypt a view or an SP in SQL server 2005 by using the key work "with encryption" while creating the SP or View.


Please look into the example below.

create procedure MySp with encryption
as
begin
select * from EmailList
end

Once you created an sp or view with the above option added then it cannot be viewed by any users.if the suer tryes to view the above sp orview then it SQL server will show a message like . The text for object 'MySp' is encrypted.

One note of caution. Save the original text of the stored procedure before encrypting it, as there is no straightforward way to decode the encrypted text. One hack is to attach a debugger to the server process and retrieve the decrypted procedure from memory at runtime


Please look to the below link for how to decrypt the encrypted Sp or view.

http://www.sql-shield.com/decrypt-stored-procedure.html

Monday, April 26, 2010

How to hide Validation summary at client side using Java Script?

The below script will help you to hide Validationsummary at client side .

How set focus to a control in a ModalPopupExtender while loading and hiding?(add_shown & add_hiding ModalPopupExtender Events )

In this topic, I’ll discuss the Client events we usually need while using ModalPopupExtender. The add_shown fires when the ModalPopupExtender had shown and add_hiding fires when the user cancels it by CancelControlID,note that it fires before hiding the modal.


They are useful in many cases, for example may you need to set focus to specific Textbox when the user display the modal, or if you need to reset the controls values inside the Modal after it has been hidden.

You can attach your fucntions  by using the Sys.Application.add_load(functionName)
Note :"functionName" should be the name of the function which is used to initialize the events add_hiding and add_shown of the ModalPopupExtender

Inside the fucntion "functionname" you can attach the your functions to the events like below



Please go through the full expample below to understand the woking of these events better.

Sunday, April 25, 2010

How check a constraint with if exixts in sql server 2005?

By using below script you will be able to check the contraint with if exist.

if not exists(SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME='CrmUserHirarchey' AND CONSTRAINT_NAME='FK_CrmUserHirarchey_aUsergroups' ) begin ALTER TABLE [dbo].[CrmUserHirarchey] WITH CHECK ADD CONSTRAINT [FK_CrmUserHirarchey_aUsergroups] FOREIGN KEY([UserGroupID], [CompanyId]) REFERENCES [dbo].[aUsergroups] ([UserGroupID], [CompanyID]) ALTER TABLE [dbo].[CrmUserHirarchey] CHECK CONSTRAINT [FK_CrmUserHirarchey_aUsergroups] end

How to append a double quotes to a string varibale in c# .net (“)?

You can add double quots to a string varibale in C# like below.

Please find below an example, how theses values is passed to a javascript fucntion to show it in message box while chicking on an image.

How to append a double quotes to a string in c# .net (“)?

You can add double quots to a  string in C# like below.
string Name = @"""Helloworld""";

Please find below an example, how theses values is passed to a javascript fucntion to show it in message box while chicking on an image.

Friday, April 23, 2010

Having trouble stepping into a stored procedure Visual studio (get canceled by user)

This error can be solved by adding your logged in user account as sysadmin user in SQL server .

How to assign value to asp.net literal or Label using JavaScript?

For an asp.net Label you can assign value using the innerText property


For an asp.net Literal you can assign value using the innerHTML property


How to add comments in my CSS (style sheet)?

CSS Commenting is very simple as any other language. Your comments should be in between /* and */. Here is an example of how to have comments
 /* this is a comment*/

Saturday, April 10, 2010

Showing Updateprogress in a model window using Ajax modal popup extender

The below code will help you you to show an Ajax update progress in a Modal popup extender like the screen shot below.
The below code assumes the current page is under a master page.
Source code

Thursday, April 8, 2010

Why UpdateProgress Not Showing?

In the following scenarios, the UpdateProgress control will not display automatically:

The UpdateProgress control is associated with a specific update panel, but the asynchronous postback results from a control that is not inside that update panel.

The UpdateProgress control is not associated with any UpdatePanel control, and the asynchronous postback does not result from a control that is not inside an UpdatePanel and is not a trigger. For example, the update is performed in code.

For making the ajax update progress to be working in the above senarion, follow as descibed below.

Underneath the "asp:ScriptManager" element, add the following script:

Replace 'UpdateProgress1' with your Udateprogressbar id and replace 'Button1' with your trigering control id.


More info can be found at
http://www.asp.net/AJAX/Documentation/Live/tutorials/ProgrammingUpdateProgress.aspx

Tuesday, April 6, 2010

Can view in SQL server 2005 be updated,inserted or deleted

Updatable Views
You can modify the data of an underlying base table through a view, as long as the following conditions are true:

Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
The columns being modified in the view must directly reference the underlying data in the table columns. The columns cannot be derived in any other way, such as through the following:
An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP.
A computation. The column cannot be computed from an expression that uses other columns. Columns that are formed by using the set operators UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a computation and are also not updatable.
The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses.
TOP is not used anywhere in the select_statement of the view together with the WITH CHECK OPTION clause.
The previous restrictions apply to any subqueries in the FROM clause of the view, just as they apply to the view itself. Generally, the Database Engine must be able to unambiguously trace modifications from the view definition to one base table. For more information, see Modifying Data Through a View.

If the previous restrictions prevent you from modifying data directly through a view, consider the following options:

INSTEAD OF Triggers
INSTEAD OF triggers can be created on a view to make a view updatable. The INSTEAD OF trigger is executed instead of the data modification statement on which the trigger is defined. This trigger lets the user specify the set of actions that must happen to process the data modification statement. Therefore, if an INSTEAD OF trigger exists for a view on a specific data modification statement (INSERT, UPDATE, or DELETE), the corresponding view is updatable through that statement. For more information about INSTEAD OF triggers, see Designing INSTEAD OF Triggers.
Partitioned Views
If the view is a partitioned view, the view is updatable, subject to certain restrictions. When it is needed, the Database Engine distinguishes local partitioned views as the views in which all participating tables and the view are on the same instance of SQL Server, and distributed partitioned views as the views in which at least one of the tables in the view resides on a different or remote server.
For more information about partitioned views, see Creating Partitioned Views.

Thursday, March 18, 2010

C# equivalent of sql server’s IsNull() function

For converting a null value to some other values, you can use the the null coalescing (??) operator: as shown below.

string Message = null;
string result = Message ?? "No data";
Response.Write(result);
 
The above code will print "No data" if executed.
 
You can find more information in the below link.
http://weblogs.asp.net/scottgu/archive/2007/09/20/the-new-c-null-coalescing-operator-and-using-it-with-linq.aspx

Wednesday, March 10, 2010

How to port a select result from one table to a new table?

select * into xxxx from dbo.Crm_Company_Calender

Relace XXXX with your new table name.All the resilt from the select querry will be ported to the new table xxxx

How to Install Advetureworks DB from SQL Setup?

1.From Add or Remove Programs, select Microsoft SQL Server 2005 and click Change. Follow the steps in the Microsoft SQL Server 2005 Maintenance wizard.

2.From Component Selection, select Workstation Components and then click Next.

3.From Welcome to the SQL Server Installation Wizard, click Next.

4.From System Configuration Check, click Next.

5.From Change or Remove Instance, click Change Installed Components.

6.From Feature Selection, expand the Documentation, Samples, and Sample Databases node.

7.Select Sample Code and Applications.

8.Expand Sample Databases and then select the sample databases to be installed. Click Next.

9.To install and attach the sample databases, from Sample Databases Setup, select Install and attach sample databases, and then click Next.
The database files are created and stored in the folder :\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data. The database is attached and ready for use.

Tuesday, March 9, 2010

How to Show a SSRS Report in a Windows Application?

Requesting a Server Report
reportViewer.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Remote;
// Get the Report Server endpoint from the application
// config file
reportViewer.ServerReport.ReportServerUrl = new
Uri(Settings.Default.ReportServerEndPoint);
reportViewer.ServerReport.ReportPath ="/Prologika/Customer Orders";
reportViewer.RefreshReport();
Handling Report Parameters
ReportParameter[] parameters = new ReportParameter[2];
parameters[0] = new ReportParameter("Date", "1/1/2003");
parameters[1] = new ReportParameter("CustomerID",
new string[] { "14335", "15094" });
reportViewer.ServerReport.SetParameters(parameters);

Monday, March 8, 2010

How to generate self-signed Secure Sockets Layer (SSL) certificate for Internet Information Services (IIS) 6.0?

SelfSSL version 1.0 is a command-line executable tool that you can use to generate and install a self-signed Secure Sockets Layer (SSL) certificate for Internet Information Services (IIS) 6.0. Because SelfSSL generates a self-signed certificate that does not originate from a commonly trusted source, the tool's usefulness is limited to two specific scenarios:

Download IIS 6.0 Resource Kit Tools from link

http://www.microsoft.com/downloads/details.aspx?FamilyID=56FC92EE-A71A-4C73-B628-ADE629C89499&displaylang=en

And use

SelfSSL version 1.0

SelfSSL (SelfSSL.exe) can help you generate and install a self-signed SSL certificate. Because the SelfSSL tool generates a self-signed certificate that does not originate from a trusted source, use the SelfSSL tool only in the following scenarios:
• When you have to create a security-enhanced private channel between your server and a limited, known group of users
• When you have to troubleshoot third-party certificate problem

You can find this exe in start->All Programs -> IIS Resources-> SelfSSL-> SelfSSL.exe

More information regarding "IIS 6.0 Resource Kit Tools " can be found at the below link
http://support.microsoft.com/kb/840671

Friday, February 19, 2010

How to delete a custom event log source?

Go to [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog]
and delete your custom log folder

Sunday, January 31, 2010

How to know the physical location of a databse in SQL?

Go to SQL Server Management Studio and open a new query pane.

Copy and paste the following querry to verify the physical path of 'mydb'

Replace 'mydb' with your database.

SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID('mydb')

Cick Execute.

In the physical_name column, you should see the path to the new location

Wednesday, January 27, 2010

How to check the Database compatibility level in SQL 2005?

Use the below commands to check and change a db compatibility level

To check compatibility level exec sp_dbcmptlevel 'yourdbname'
Eg: exec sp_dbcmptlevel 'yourdbname'


To change compatibility level exec sp_dbcmptlevel 'yourdbname',80
Eg: exec sp_dbcmptlevel 'yourdbname',90

Monday, January 25, 2010

Page cannot be found" when browsing aspx pages in Windows Server 2003 with IIS 6.0

You may get a Page cannot be found message when you browse aspx pages in a Windows Server 2003 environment.

That is because in Windows 2003, all the webservice extensions are "Prohibited" by default to ensure security.

To resolve this, do the following steps:-

1. From your Run command, type inetmgr and press enter.
2. Expand the appropriate nodes in the IIS to locate the "Webservice Extensions" Node
3. Click on the same.
4. You will find a list of "prohibited" extensions in the right.
5. Click on ASP.NET and Active Server Pages and "allow" it

That should resolve this issue.

This article applies for Windows Server 2003, IIS 6.0 environment

Happy Supporting

Rajesh Kamalakshan