,

Windows Event Starting up database DatabaseName

Configuration:-
Windows Server 2003 R2 32 bit
Sql Express 2008 R2

While checking for server event as a part of maintenance we a information which is occuring after every 1-10 seconds the information is Event "Starting up database DatabaseName"

We found the solution and implemnted the same.

You need to open "Sql Express Management Studio>>Database>>Properties>>Options>>Auto Close" and set it to false.

For more information on this property, please refer
http://blogs.msdn.com/b/buckwoody/archive/2009/06/24/sql-server-best-practices-autoclose-should-be-off.aspx
http://msdn.microsoft.com/en-us/library/ms135094%28SQL.90%29.aspx
Share:
Read More
, ,

How to set focus on Table row using Javascript

We are developing Application for Google Smart TV and all is going well.

We are using Table, Div or some other elements which cannot be focused on using .focus() of java script.

We have used Table to show data in one of our page. Our target is to set the focus on first element of table i.e. first row.

We tried different solutions suggested on web but nothing worked. All the posts are suggesting to use focusable controls like text box, check box etc.

Finally we found solution on http://groups.google.com/group/mozilla.dev.tech.css/browse_thread/thread/42591922d95c6399

In the post "Stanimir Stamenkov" has used a term "if you just define a 'tabindex' on the element it becomes focusable" I assigned "tabindex" property to table row and then used .focus() and the focus reached to row.


Hope this will help all who are looking for such nice solutions.
Share:
Read More
,

How to allow special characters in URL or query string

I am using asp.net 4.0 with Sql server. I have an requirement to pass special characters in URL query string.

for example my URL need to be like http://mysite.com/default.aspx?a=xyx(abc)
In the above URL my special character is "(" and ")". While development I have not faced any issue but as I uploaded the files to serve it start giving error 404 (page not found) where ever I have use "(" or ")" special characters.

When I started searching I have tried many solutions. but nothing works for me.
Then on some site some one has sugested to check IIS log.

When I checked the log I found that I have Installed Microsoft URL Scan 3.1 on my server which is filtering the URL.

So, I need to allow "(" and ")" on my server so, I decided to allow there characters in my URL.

So, to add exception to URL Scan 3.1 you need to open urlscan.ini which you can find in "%windir%\system32\inetsrv\urlscan\"

You can use 2 sections to allow special characters
1) DenyQueryStringSequences
2) AlwaysAllowedUrls


DenyQueryStringSequences - In this section you can add and remove the allowed characters but this will allow for all the URLs.

AlwaysAllowedUrls - In this you can define a single URL like "/default.aspx".So, the special characters will be allowed to only single URL not to all the URL of the IIS sites

Share:
Read More
, , , , , ,

How to select data from another sql server

We have a target to run a JOB on server to import data from another SQL server instance.

For example take
Server 1 - Main
Server 2 - From which we have to import.

If you have admin rights on both the servers you can "Link the servers" under "Server Objects>>Linked Servers" Right click on the same and provide all the parameters of server or as an alternate you can run following command.

EXEC sp_addlinkedserver
@server = 'db1',
@srvproduct = 'SQLServer OLEDB Provider',
 @provider = 'SQLOLEDB',
 @datasrc = 'server2',
 @provstr='User Id=sa; Password=abc'

The above command parameters:-
 @server- An identification name of server.
@datasrc- Your server instance name or IP.

Your SQL will look like:-
Select * from db1.dbname.dbo.tablename

If sometimes the server will get changed, the above statement gives you the option to change the user name, password and server at any points of time without effecting the relevant SQL and SP written the basis of same.

Second Method (You can use the same if you does not have admin rights to add Linked server)

SELECT   *
FROM      OPENDATASOURCE(
         'SQLOLEDB',
         'Data Source=Server2;User ID=sa;Password=abc'
         ).dbname.dbo.tablename
        

In the above case you have to hard code all the parameters which you have to change in all the SQL and SP if something will get changed in future. So, I prefer to use Linked Server
Share:
Read More
, ,

How to resolve "crdb_adoplus.dl" issue

With the launch of VS 2010, we start using VS 2010 and used the new improved IDE and features of VS 2010.

While woring with a windows based application we have requirement to use Crystal Report. We are able to add and design a new Crystal Report without facing any problem.

After writing the code to show data, we start getting a unique problem of "crdb_adoplus.dl". We searched for many solution and finally find the solution.

We added the following attributes in app.config

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

So, the final app.config will be :-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

Reference :

http://social.msdn.microsoft.com/Forums/eu/vscrystalreports/thread/2503389c-6d25-48d3-bb15-25ed67f52f21
Share:
Read More
, , , , , , , , , , , ,

How to set max limt of File Upload in Asp.net

Many times I faced the same problem with all my applications, that is Max size of file to be uploaded to server.

By default, the maximum size limit of a file to be uploaded to a server using the ASP.NET FileUpload control is 4MB. You cannot upload anything that is larger than this limit.

If you wants to upload a file more the size of 4 MB which is by default, you have to make some changes in the application's web.config:

<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>

Below is the small description of the parameters attributes.

maxRequestLength - Attribute limits the file upload size for ASP.NET application. This limit can be used to prevent denial of service attacks (DOS) caused by users posting large files to the server. The size specified is in kilobytes. As mentioned earlier, the default is "4096" (4 MB). Max value is "1048576" (1 GB) for .NET Framework 1.0/1.1 and "2097151" (2 GB) for .NET Framework 2.0.

executionTimeout - Attribute indicates the maximum number of seconds that a request is allowed to execute before being automatically shut down by the application. The executionTimeout value should always be longer than the amount of time that the upload process can take.
Share:
Read More
, , ,

How to Get/Set date time according to Different Time zones in C#

downloadDownload code example

In an Asp.net application I have developed a Forum in which I have requirement to show date and time according to the time zone of PC on which it is running, I had searched for too many examples on but all are using too complex java scripts and other methods to convert time into local time zone.

Finally I decided to make my own solution for this problem
My solution is using “TimeZoneInfo” to convert the data to local time zone, this class allow me to convert time according to any time zone, but again I got another problem which is how to take time zone of browser. Again I search on net and finally come out with a code.

<script language="javascript" type="text/javascript">
    function genarateDateValue()
    {             
        var d = new Date()      
        var str=d.toString();
        var i = str.indexOf("+");      
        var j = str.length- i;
      
        str=str.substring(i, i+5);      
        setCookie("narender",str,365);
        return true;
       }

    function setCookie(c_name,value,expiredays)
    {      
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    }  
</script>

In Sql Server still there is no method to covert from one time zone to another but My Sql Support converting date time according to provided time zone.
Following is the simple code runs on My Sql Prompt:-
CONVERT_TZ(dt,from_tz,to_tz)
CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. This function returns NULL if the arguments are invalid.
If the value falls out of the supported range of the TIMESTAMP type when converted from from_tz to UTC, no conversion occurs.
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
        -> '2004-01-01 13:00:00'
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
        -> '2004-01-01 22:00:00'

Above is the method which we can use in My Sql which will return all the values from Database itself but if we are using Sql server we need to write our own code to convert time zone in C# code.
You can also download this code from link provided on top on this post.
public string DateFormat(string str)
    {
        ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
        foreach (TimeZoneInfo timeZone in timeZones)
        {
            TimeSpan offsetFromUtc = timeZone.BaseUtcOffset;
            string offsetString;
            string strHours = string.Empty;
            string strMinutes = string.Empty;
            strHours = offsetFromUtc.Hours.ToString();
            strMinutes = offsetFromUtc.Minutes.ToString();
            if (strMinutes.Length == 1)
            {
                strMinutes = "0" + strMinutes;
            }
            if (strHours.Length == 1)
            {
                strHours = "0" + strHours;
            }

            if (Convert.ToInt32(offsetFromUtc.Hours) >= 0)
            {
                strHours = "+" + strHours;
            }
            offsetString = strHours + strMinutes;
            if (Request.Cookies["narender"] != null)
            {
                if (Request.Cookies["narender"].Value.ToString() == offsetString)
                {
                    if (str != "")
                    {
                        DateTime thisTime = Convert.ToDateTime(str);
                        TimeZoneInfo tst1 = TimeZoneInfo.FindSystemTimeZoneById(timeZone.Id);
                        DateTime tstTime1 = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst1);
                        str = Convert.ToDateTime(tstTime1).ToString("dddd,MMMM dd,yyyy hh:mm:ss tt");
                    }
                    return str;
                }
            }
        }
        return str;
    }
Share:
Read More
, , , , , , , ,

How to zip a file or folder using C#

downloadDownload code example


I had searched a lot to make files zip using c#, all the solution provided only support to zip a single file but my requirement is to zip a directory selected by used, I had tried so many utilities but unfortunately all does not works for me.

Finally I found a solution which is using Java utility to zip file. This solution is quite easy to implement and debug.

To implement this solution you need to add reference of “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vjslib.dll” to your application.
Share:
Read More
, , , , , , , ,

How to pass server values to Javascript using Eval()

In my application I have a target to show message if user does not have permission to navigate to another page. I can do this by using server code but it will make a round trip to server and make a bad user experience so, I decided to use java script.

Following is the function of Java Script

<script language="javascript" type="text/javascript">
function func_Message(obj)
{
if (parseFloat(obj)>0)
{
return true;
}
else
{
alert("Please assign a value before viewing the details");
return false;
}
}
</script>


And following is the code of Link Button from where I am passing value to Java Script Function

<asp:LinkButton ID="lnk_Details" runat="server" Text="Details" CommandArgument='<%# Eval("festi_id") +"~" + Eval("user_id") %>'
CommandName="ViewDetails" OnClientClick='<%# "return func_Message(" + Eval("user_id") + ");"%>'></asp:LinkButton>
Share:
Read More