Monday, 25 April 2011

The 'RadLangSvc.Package, RadLangSvc.VS, Version = 10.0.0.0, Culture = neutral, PublicKeyToken = 89845dcd8080cc91' failed to load

A couple of days ago, using the Schema Compare tool included in Visual Studio 2010 Ultimate, I ran into an error that reads:

"The 'RadLangSvc.Package, RadLangSvc.VS, Version = 10.0.0.0, Culture = neutral, PublicKeyToken = 89845dcd8080cc91' package did not load Correctly."

The system continues to operate apparently, only after the settings when we kick off the comparison, the environment crashes fatal.
After a little 'research I found this post which in turn refers to that.

The problem is essentially due to the installation of SQL Server 2008 R2, which affected various components associated with the SQL scripting. The same symptoms occur it is also using the SQL shell included in VS, even though I had installed the R2 for a while, 'I have not noticed it before because I always use the environment to SQL Server Management Studio.
The proposed solution is to simply re-run the post installation

DACProjectSystemSetup_enu.msi

located on the installation disc in the folder of VS 2010

\ WCU \ DAC

but for more serious problems may need to rerun the other two in the same folder installer

TSqlLanguageService_enu.msi
DACFramework_enu.msi

take care of it in VS closed and once the installation is complete, there is no need to restart everything is already back in place.

Sunday, 17 April 2011

Determining which key is pressed using java script or Working withjavascript key codes

The following example is used to determine which key is pressed using javascript
<script type="text/javascript">
function displayunicode(e){
var unicode=e.keyCode? e.keyCode : e.charCode
alert(unicode)
}
</script>
<form>
<input type="text" size="2" maxlength="1"
onkeyup="displayunicode(event); this.select()" />
</form>

Working with jquery key events

The key events are always required to use in application when we dont want to use mouse. the following is the example to handle key events using key codes in jqurery. for all javascript key codes refer http://vikramdoda.wordpress.com/2011/04/10/javascript-key-codes/

Syntax for handle keypress event is
.keypress( [ eventData ], handler(eventObject) )
eventDataA map of data that will be passed to the event handler.
handler(eventObject)A function to execute each time the event is triggered.
<script> var xTriggered = 0;
 $('#target').keypress(function(event) { 
  if (event.which == '13') {   
   event.preventDefault();   
 }  
  xTriggered++;   
 var msg = 'Handler for .keypress() called ' + xTriggered + ' time(s).';  
 $.print(msg, 'html'); 
  $.print(event);
 });
 </script>

Thursday, 14 April 2011

Restoring SQL Server Database from .bak files

Restoring MSSQL Database from .bak files

1. Open SQL Server Management Studio on your local machine.
2. Right click the Databases folder. From the pop-up menu, select New Database.
3. Enter a database name, and then click Ok.
4. Right click the new database icon. From the pop-up menu, select Tasks -> Restore -> Database.
5. Select the From Device option, and then click the browse button.
6. Click Add and navigate to the appropriate file. Click Ok.
7. In the Restore Database window, select the checkbox next to your .bak file.
8. Switch to the Options page. Select the Overwrite the existing databasecheckbox.
9. Click Ok.
10. Verify the contents of your database, which is now active on your local machine.

Unable to launch the application because port 'N' already in use.

I had a similar problem.  I found it to be related to the Eset personal security (guessing a recent update messed something up). To solve it I excluded VS2008 from the active browser filtering - this is in: setup -> advanced firewall setup -> antivirus & anti spyware -> web access protection -> HTTP -> webbrowsers

Deselecting vsdev in here fixed the problem - interestingly enough disabling the firewall and antivirus / antispyware did not solve the issue, so it is worth looking for a similar setting if you are running different security software

Restoring SQL Server Database from .mdf files

Restoring MSSQL Database from .mdf files

1. Open SQL Server Management Studio on your local machine.
2. Right click the Databases folder. From the pop-up menu, select Attach.
3. Click Add and select the appropriate .mdf file. Click Ok, and then click Ok again.
4. Verify the contents of your database, which is now active on your local machine.

How to run MVC3 Razor Application on IIS6

IIS6 Extension-less URLs

All the MVC3 razor application are not having any extension files. The IIS6 is not understand the extension less urls by default. In order to solve this problem the solution is as follow:

The extension-less URLs using the infamous “Star mapping” or “Wildcard mapping” feature of IIS 6. I say infamous because there is a lot of concern over the performance implications of doing this. Of course, you should measure the performance of your site for yourself to determine if it is really a problem.

Steps
  1. Go to Run-->Inetmgr-->then expand your website-->select virtual directory-->righclick-->properties.
  2. Click on Configuration-->Application Configuration Properties dialog will open.
  3. Select .aspx in application fileextensions--->clik on Edit. then Add/edit application extension mappind dialog will open.
  4. Copy the executable text-->click on cancel.
  5. Go back to Application Configuration dialog-->Click on inset beside the Wild card application maps
  6. then paste the executable text which is copied previously(that is nothing but isapi filter file path). Uncheck verify that file exits. dont forget to uncheck Verify that file exists. Click on ok.
  7. Restart iis.
  8. Now run your application.

Wednesday, 13 April 2011

SQL Server 2008 Setup on Windows Fail With “The system cannot find thepath specified”

  • Clean SQL 2008 components using the command line given at the top of the Summary.txt file:
    setup /q /action=uninstall /instanceid=MSSQLSERVERfeatures=SQLEngine,Replication,FullText
    OR
    Use Add\Remove Programs to clean the installed components.
  • Do not remove 100 folder inside C:\Program Files\Microsoft SQL Server\..
  • Now, run rsfx.msi file from ..\Installation folder\[x86] or [x64] or [ia64]\Setup folder. This will create the RsFxInstall folder and .ini files inside ..\100\Shared.
  • Then start the slipstream setup again.

Sql Server 2008 Installation failed


If already sql server is installed in your system. if you want to upgrade or reinstalling fails
then follow the given steps

  1.  Stop IIS Admin Service
  2.  Stop IIS
  3. Uninstall SQL Server previously installed.
  4.  Start new installation

Tuesday, 12 April 2011

Get the current page url using javascript

The following code line is used to get the current page url:
var currentPage=parent.document.URL.toString();

Getting jQuery Intellisense in Razor pages


Get jQuery Intellisense by adding this to a page:
@if(false)
{
<script src="../../Scripts/jquery-1.4.2-vsdoc.js" language="javascript" />
}

Sunday, 10 April 2011

Javascript Key codes

Here is the list of key codes to handle key events in javascript.
Key Pressed Javascript Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222

All Sql Server Connection Properties for creating Connection String

There are plenty of combinations when creating an SQL Server connection string. This reference table explains each option available per keyword.

Introduction
This table shows all connection string properties for the ADO.NET SqlConnection object. Most of the properties are also used in ADO. Using this table will give you a better understanding of the options available.

The Properties
Some of the keywords have several equivalents. For those, each variant is specified on its own line separated with "-or-".
Name Default Description
Application Name The name of the application, or '.Net SqlClient Data Provider' if no applicationname is provided.
Async 'false' When true, enables asynchronous operation support. Recognized values are true, false, yes, and no.
AttachDBFilename
-or-
extended properties
-or-
Initial File Name
The name of the primary database file, including the full path name of an attachable database. AttachDBFilename is only supported for primary data files with an .mdf extension. The attachment will fail if the primary data file is read-only. The path may be absolute or relative by using the DataDirectory substitution string. If DataDirectory is used, the database file must exist within a subdirectory of the directory pointed to by the substitution string.

Note that remote servers, HTTP, and UNC (\\server\sharename\folder\) path names are not supported.

The database name must be specified with the keyword 'database' (or one of its aliases) as in the following: "AttachDbFileName=|DataDirectory|\data\YourDB.mdf; integrated security=true;database=YourDatabase". An error will be generated if a log file exists in the same directory as the data file and the 'database' keyword is used when attaching the primary data file. In this case, remove the log file. Once the database is attached, a new log file will be automatically generated based on the physical path.
Connect Timeout
-or-
Connection Timeout
15 The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.
Connection Lifetime 0 When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. This is useful in clustered configurations to force load balancing between a running server and a server just brought online. A value of zero (0) causes pooled connections to have the maximum connection timeout.
Context Connection 'false' true if an in-process connection to SQL Server should be made.
Connection Reset 'true' Determines whether the database connection is reset when being removed from the pool. Setting to 'false' avoids making an additional server round-trip when obtaining a connection, but the programmer must be aware that the connection state is not being reset.
Current Language The SQL Server Language record name.
Data Source
-or-
Server
-or-
Address
-or-
Addr
-or-
Network Address
The name or network address of the instance of SQL Server to which to connect. The port number can be specified after the server name: server=tcp:servername, portnumber. When specifying a local instance, always use (local). To force a protocol, add one of the following prefixes: np:(local), tcp:(local), lpc:(local)

ADO.NET 2.0 does not support asynchronous commands over shared memory for SQL Server 2000 or earlier. However, you can force the use of TCP instead of shared memory, either by prefixing tcp: to the server name in the connection string, or by using localhost.
Encrypt 'false' When true, SQL Server uses SSL encryption for all data sent between the client and server if the server has a certificate installed. Recognized values are true, false, yes, and no.
Enlist 'true' When true, the pooler automatically enlists the connection in the creation thread's current transaction context. Recognized values are true, false, yes, and no.
Failover Partner N/A The name of the failover partner server where database mirroring is configured. The Failover Partner keyword is not supported by .NET Framework version 1.0 or 1.1.
Initial Catalog
-or-
Database
The name of the database.
Load Balance Timeout 0 The minimum time, in seconds, for the connection to live in the connection pool before being destroyed.
MultipleActiveResultSets 'false' When true, an application can maintain multiple active result sets (MARS). When false, an application must process or cancel all result sets from one batch before it can execute any other batch on that connection. Recognized values are true and false. The keyword is not supported by .NET Framework version 1.0 or 1.1.
Integrated Security
-or-
Trusted_Connection
'false' Whether the connection is to be a secure connection or not. Recognized values are 'true', 'false', and 'sspi', which is equivalent to 'true'.
Max Pool Size 100 The maximum number of connections allowed in the pool.
Min Pool Size 0 The minimum number of connections allowed in the pool.
Network Library
-or-
Net
'dbmssocn' The network library used to establish a connection to an instance of SQL Server. Supported values include dbnmpntw (Named Pipes), dbmsrpcn (Multiprotocol, Windows RPC), dbmsadsn (Apple Talk), dbmsgnet (VIA), dbmslpcn (Shared Memory, local machine only) and dbmsspxn (IPX/SPX), dbmssocn (TCP/IP) and Dbmsvinn (Banyan Vines).
The corresponding network DLL must be installed on the system to which you connect. If you do not specify a network and you use a local server (for example, "." or "(local)"), shared memory is used.
Packet Size 8192 Size in bytes of the network packets used to communicate with an instance of SQL Server.
Password
-or-
Pwd
The password for the SQL Server account logging on. Not used with (the strongly recommended) 'Integrated Security=true' option.
Persist Security Info 'false' When set to 'false' (strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password.
Pooling 'true' When true, the SQLConnection object is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool. Recognized values are true, false, yes, and no.
Replication 'false' true if replication is supported using the connection.
Transaction Binding Implicit Unbind Controls connection association with an enlisted System.Transactions transaction. Possible values are:
Transaction Binding=Implicit Unbind;
Transaction Binding=Explicit Unbind;
Implicit Unbind causes the connection to detach from the transaction when it ends. After detaching, additional requests on the connection are performed in autocommit mode. The System.Transactions.Transaction.Current property is not checked when executing requests while the transaction is active. After the transaction has ended, additional requests are performed in autocommit mode.
Explicit Unbind causes the connection to remain attached to the transaction until the connection is closed or an explicit SqlConnection.TransactionEnlist(null) is called. An InvalidOperationException is thrown if Transaction.Current is not the enlisted transaction or if the enlisted transaction is not active.
TrustServerCertificate 'false' When set to true, SSL is used to encrypt the channel when bypassing walking the certificate chain to validate trust. If TrustServerCertificate is set to true and Encrypt is set to false, the channel is not encrypted. Recognized values are true, false, yes, and no.
Type System Version N/A A string value that indicates the type system the application expects. Possible values are:
Type System Version=SQL Server 2000;
Type System Version=SQL Server 2005;
Type System Version=SQL Server 2008;
Type System Version=Latest;
When set to SQL Server 2000, the SQL Server 2000 type system is used. The following conversions are performed when connecting to a SQL Server 2005 instance:
XML to NTEXT
UDT to VARBINARY
VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) to TEXT, NEXT and IMAGE respectively.
When set to SQL Server 2005, the SQL Server 2005 type system is used. No conversions are made for the current version of ADO.NET.
When set to Latest, the latest version than this client-server pair can handle is used. This will automatically move forward as the client and server components are upgraded.
User ID The SQL Server login account.
User Instance 'false' A value that indicates whether to redirect the connection from the default SQL Server Express instance to a runtime-initiated instance running under the account of the caller.
Workstation ID The local computer name The name of the workstation connecting to SQL Server.

Summary

There is no point in always defining each of these properties. Return to this sheet to look up definitions as a way to ensure proper connections. Also use this as a reference to ensure that you have included every property applicable to your specific situation.

IP Addresses & Categories

IP address is the logical address to identify the device in network.

IP address are of two types
  1. IPv4
  2. IPv6
In IPv4 32bits are divided into four octates. Each octate is separed with dot(.) and its known as dotted decimal notation. Total 4.3 billion IP address are again divided into 5 classes i.e., is from Class A,B,C,D,E based on priority bits. Priority bits are most significant bits from most significant octates.
Class First octet range Priority bit Octet format Usage
A 0-127 0 N.H.H.H Large Networks
B 128-191 10 N.N.H.H Medium Networks
C 192-223 110 N.N.N.H Small Networks
D 224-239 1110 - Reserved for multicasting
E 240-255 1111 - Resrved for research and development
To calculate
Number of networks=2N-P
where N=number of network bits and P=number of priority bits

Number of Hosts=2H-2
where H=number of host bits

Network ID: Network ID is used for representing the network. It represents group of IP addresses. By default network ID contains 0 in the host portion.
First IP of the network is the network ID. ex: 192.168.1.0

Broadcast ID:
Broadcast ID is used for broadcasting the information to other IP addresses which is belongs to same network. By default broadcast contains 255 in the host portion.
Last IP address of the network is broadcast ID. ex: 192.168.1.255

Valid IP address: Valid IP addresses exit between network ID and broadcast ID
Ex:192.168.1.2

Public IP addresses:
Public IP addresses are the valid IP addresses which are routable over the internet. These IP addresses are not free of cost. Inorder to access them we have to purchase from Internet Service Providers(ISP).

Private IP addresses: Certain addresses from each class of the IP address are reserved for private networks. These addresses are called private IP address. These private IP addresses are not valid over the internet.

Private IP address from each class
Class A 10.0.0.0 - 10.255.255.255
Class B 172.16.0.0 - 172.31.255.255
Class C 192.168.0.0 - 192.168.255.255
Exclusion Range of IP address
  • 0.0.0.0 is completely excluded from IP address range. it is called global ip.

  • 127.x.x.x range of IP addresses are also excluded. It is called loopback addresses. It is used to check the compatability of Network Interface Card(NIC) with operating system as well as functionality of TCP/IP.
  • 255.255.255.255 is also excluded. It is called broadcast ID.
NOTE:
169.254.0.0 - 169.254.255.255 Special range ip address used for dynamic purposes when we are using Dynamic Host Control Protocol(DHCP) to assign ip addresses. If no ip addresses available or any network problem raises this special range ip addresses are asigned by DHCP server.

Friday, 1 April 2011

Identifying control raising postback event

This should get you the control that caused the postback:
public static Control GetPostBackControl(Page page)
{
    Control control = null;
    string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    if (ctrlname != null && ctrlname != string.Empty)
    {
        control = page.FindControl(ctrlname);
    }
    else
    {
        foreach (string ctl in page.Request.Form)
        {
            Control c = page.FindControl(ctl);
            if (c is Button || c is ImageButton)
            {
                control = c;
                break;
            }
        }
    }
    return control;
}

Read more about this on this page: http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx

List of Protocols and Their Port Numbers

Here are the List of Protocols and their Port Numbers along with registered and unregistered.

How to get Asp.net Control ClientID in external javascript file

Every asp.net developer knows that Every control which is running at server in asp.net application changes the id of the control while rendering into the browser. If it is an Internal script we can access using '<%=ConrolId.ClientID>'. But we cann't access like this in external javascript file.

Solution to access the Serverside control in External javascript file:

Step1:We need to declare two arrays; the first array will have the server IDs of the required controls, and the  second array will have the client IDs of the server controls in the same order.

Step2: Register these two arrays at the client side.

Step3:Now, create a JavaScript function which will accept the server ID and will compare the server ID with the available server IDs in the array and will give its position in the array. Then, the same function would return you the matching client ID from the same location in the client IDs array.

The code below shows the declaration of the array, and the declaration of the JavaScript function in the code-behind.
/* This is the method used to register the array
of the clientid's as well as the serverid's
Also this method registers the function GetClientId, which is used
to get the client id provided server id is supplied */

public void RenderJavaScriptArrayWithCliendIds(params Control[] wc)
{
if (wc.Length > 0)
{
StringBuilder arrClientIDValue = new StringBuilder();
StringBuilder arrServerIDValue = new StringBuilder();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Now loop through the controls and build
//the client and server id's
for (int i = 0; i < wc.Length; i++)
{
arrClientIDValue.Append("\"" +
wc[i].ClientID + "\",");
arrServerIDValue.Append("\"" +
wc[i].ID + "\",");
}

// Register the array of client and server id to the client
cs.RegisterArrayDeclaration("MyClientID",
arrClientIDValue.ToString().
Remove(arrClientIDValue.ToString().Length - 1, 1));
cs.RegisterArrayDeclaration("MyServerID",
arrServerIDValue.ToString().
Remove(arrServerIDValue.ToString().Length - 1, 1));

// Now register the method GetClientId,
// used to get the client id of tthe control
cs.RegisterStartupScript(this.Page.GetType(), "key",
"\nfunction GetClientId(serverId)\n"+
"{\nfor(i=0; i<MyServerID.length; i++)" +
"\n{\nif ( MyServerID[i] == serverId )\n" +
"{\nreturn MyClientID[i];\nbreak;\n}\n}\n}", true);
}
}

Call the method in BasePage or BaseMaster which is accessible to all the pages
RenderJavaScriptArrayWithCliendIds(tbUserName[,tbpassword,.......]);

In the external javascript file if u want to get the clientid of tbUserName then call the javascript function as follows
var tbUserName=document.getElementById(GetClientId('tbUserName'));

This will solve any issue arising due to changes in the client IDs of controls placed inside a Master Page or Page.

List of ALL MimeTypes on the Planet, mapped to File Extensions

http://www.iana.org/assignments/media-types/ lists the "official" mime-types, but it doesn't prevent anyone making their own an not registering it with Inetenet Assigned Numbers Authority(IANA).

JavaScript fuction for ReplaceAll

The solution to replace all using javascript is as follows:
String.prototype.ReplaceAll = function(stringToFind,stringToReplace){

var temp = this;

var index = temp.indexOf(stringToFind);

while(index != -1){

temp = temp.replace(stringToFind,stringToReplace);

index = temp.indexOf(stringToFind);

}

return temp;

}

Javascript function for InitCaps

The following is the simple code for converting the given string in to the init caps using javascript
function initcaps( string ) {
/* The following  Regex Replace  will  Identify  First Character
from the Word and  makes  it to  Uppercase and remaining
text to lower case */
/* This function consider only Alphanumeric Not  any 
Special Characters.*/

string =string.replace( /(\b\w)([a-zA-Z0-9]+)/gi,
function(t,a,b) { return a.toUpperCase() + b.toLowerCase(); } );
return string;
}