Tuesday, March 27, 2012

Exception Details: System.Data.SqlClient.SqlException: Login failed for user

this is an error i got while doing DB connection in C# .
i was wondering if my connectionstring is not correct.. but that was correct...
connection string is "connectionString="Data Source=<serverName>;Database=<DBName>;User ID=<Username>;pwd=<password>;""
what i found is, things should be as follows...
1st of all the user should have teh credentials of SQL Authentication.
and next the DB instance should be of mixed security mode...
if its only Windows Authentication, and you have created the above user in SQL Authentication, then it will throw the same error...
so to make the server in moxed mode login to the server with SQL Admin credential and right click on the server name and click properties...
then got to the "Security" link and select the "SQL Server and Windows Authentication Mode"
then restart the server and try..
this should work...

thanks,
yes.sudhanshu

Unrecognized attribute ‘targetFramework’ when deploying asp.net 4.0

after hosting a site in IIS 7.0 , while accessing any server pages, i got the below error..
"Unrecognized attribute ‘targetFramework’ when deploying asp.net 4.0"

is most likely because of either of 2 reasons:

1. You installed the .net 4.0 bits after IIS was set up, resulting in the wrong version of the .NET framework beeing registered with IIS.

Most often the above results in conflicting versions of the framework, and so the easiest way of solving this is to re-register the .NET extensions with IIS using the aspnet_regiss tool. Make sure you run it from an elevated command prompt and that you use the correct version (in the v4.xx folder that is, not the v2.xx one). On my dev machine this tool is located in:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
and you run it with the -iru flags like so:
aspnet_regiis.exe -iru
then just restart the IIS if possible.

2. You haven’t set the framework of the IIS application to the correct version of .NET (4.0 that is)

Change this using either the IIS(7.) Manager or the command line. In IIS Manager you select ‘Application Pools’, just double click and you will get a pop up as in the image and change as per the highlighted one in the image.

Hope this helps...

yes.sudhanshu

Monday, March 26, 2012

asp dot net multiline textbox maxlength not working

in asp.net the maxlength attribute does not work, if the textbox is multiline.
<asp:TextBox ID="txtEvent" runat="server" MaxLength="500" TextMode="MultiLine"
                        Width="783px" Height="64px"></asp:TextBox>
if its not multiline the maxlength works properly...
this is a known issue and every body shouts...
so the work around is nothing other than the big Javascript.
so do as follows...

<asp:TextBox ID="txtEvent" runat="server" MaxLength="500" TextMode="MultiLine"
                        Width="783px" Height="64px" onKeyUp="Count(this,500);" onChange="Count(this,500);"></asp:TextBox>


The Javascript is

//check the length of the textbox(multiline)
        function Count(text, long) {
            var maxlength = new Number(long); // Change number to your max length.
            if (text.value.length > maxlength) {
                text.value = text.value.substring(0, maxlength);
                alert(" Maximum " + long + " characters allowed.");
            }
        }

hope this helps...