Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
While loading data in grid in production server I found following script Error on Page left bottom corner (This error is occurring only on production server, in local server its working fine)
This error is occurring inconsistently

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS123646; Embedded Web Browser from: http://bsalsa.com/; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Timestamp: Tue, 9 Oct 2012 12:11:23 UTC


Message: Unterminated string constant
Line: 111115201
Char: 187
Code: 0
URI: http://Domain/MYApp/MyPage.aspx




following is the code for binding data in grid
C#
 try
            {
                conGetPost.ConnectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
                conGetPost.Open();
                SqlCommand cmdGetPost = new SqlCommand();
                cmdGetPost.CommandTimeout = 999999999;
                cmdGetPost.Connection = conGetPost;
                cmdGetPost.CommandType = CommandType.StoredProcedure;
                cmdGetPost.CommandText = "MySP";
                if (wdpfrom.Value.ToString() == "1/1/0001 12:00:00 AM" || wdpTo.Value.ToString() == "1/1/0001 12:00:00 AM")
                {
                    ShowMessage("Please select proper Date range");
                    wdgPost.DataSource = "";
                    wdgPost.DataBind();
                    return;
                }
                else
                {
                    cmdGetPost.Parameters.AddWithValue("@dateFrom", wdpfrom.Value);
                    cmdGetPost.Parameters.AddWithValue("@dateTo", Convert.ToDateTime(wdpTo.Value.ToString()).Add(new TimeSpan(23, 59, 59)));
                }
                cmdGetPost.Parameters.AddWithValue("@ID", ID);
                SqlDataAdapter daGetPost = new SqlDataAdapter();
                daGetPost.SelectCommand = cmdGetPost;
                daGetPost.Fill(dsGetPost);
                if (dsGetPost.Tables.Count > 0)
                {
                    if (dsGetPost.Tables[0].Rows.Count > 750)
                    {
                        ShowMessage("Maximum record found please reduce date range");
                        wdgPost.DataSource = "";
                        wdgPost.DataBind();
                        return;
                    }
                }
                wdgPost.ClearDataSource();
                wdgPost.DataSource = dsGetPost;
                wdgPost.DataBind();
                if (dsGetPost.Tables[0].Rows.Count == 0)
                {
                    ShowMessage("No records found");
                }
                Session["dsGetPost"] = dsGetPost;
            }
catch( Exception ex)
            {
               
                return;
            }
finally
            {
                if (conGetPost != null)
                {
                    conGetPost.Close();
                    conGetPost = null;
                }
            }

How to know the line no in my C# code?
How to fix it? Please Help
Posted
Updated 9-Oct-12 2:58am
v2
Comments
I.explore.code 9-Oct-12 10:14am    
Add some error logging in your catch block and write the StackTrace to a file on your server. That should give details of any server side errors that might be happening, although, this error is a JavaScript error which probably is happening due to something not rendering properly. Make sure you don't any unterminated string constants in your markup or config file.
rajnish2patel 10-Oct-12 5:55am    
Thanks for you valuable response...

1 solution

Hi I finally solved it.

How I tracked it?
Enabling script debugging and used fiddler 2 tool and found whats going wrong. I found some error was thrown at date parsing.

What I did to solve? I wrote a method for datetime conversion as
C#
public static bool ValidateDate(string txtDate, string sDateFormat, ref string sErrMsg, ref DateTime dtDate)
        {
            if (txtDate == "")
            {
                sErrMsg = "Please Enter Date";
                return false;
            }
            else
            {
                System.Globalization.DateTimeFormatInfo dateInfo = new System.Globalization.DateTimeFormatInfo();
                dateInfo.ShortDatePattern = sDateFormat;

                try
                {
                    dtDate = Convert.ToDateTime(txtDate, dateInfo);
                    return true;
                }
                catch
                {
                    sErrMsg = "Please Enter Date In Correct Format";
                    return false;
                }
            }
        }

then I used as
string errMsg = string.Empty;
                Boolean IsFromDateValid = false;
                DateTime fromDate = new DateTime();
                IsFromDateValid = ValidateDate(wdpfrom.Text.Trim(), "dd/MM/yyyy", ref errMsg, ref fromDate);
                if (IsFromDateValid == false)
                {
                    ShowMessage(errMsg);
                    return;
                }
                Boolean IsToDateValid = false;
                DateTime toDate = new DateTime();
                IsToDateValid = ValidateDate(wdpTo.Text.Trim(), "dd/MM/yyyy", ref errMsg, ref toDate);
                if (IsToDateValid == false)
                {
                    ShowMessage(errMsg);
                    return;
                }
                else
                {
                    TimeSpan ts = new TimeSpan(23, 59, 59);
                    toDate = toDate.Add(ts);
                }

and finally passed parameter to SP as
C#
cmdGetPost.Parameters.AddWithValue("@dateFrom", fromDate);
cmdGetPost.Parameters.AddWithValue("@dateTo", toDate);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900