Olympiad Helper

Wednesday, 20 July 2011

JavaScript is not Calling Ajax Web Service on the site hosted at Godaddy Virtual Dedicated Server

We recently moved all our domains from Godaddy Shared hosting to Godaddy Virtual Dedicated Server(VDS). As we do not have expertise in Server / Domain setup, we decided to take the subscription of Plesk control panel along with the subscription of the Virtual Dedicated Server, and I will suggest every one should take this if you do not have Server setup experience.

Now when we migrated all our site to VDS, and set the domain hosting using the Plesk control panel, we started seeing that none of our JavaScript is getting fired properly, wheich is calling Ajax to call Local Web Service functions. The same code was running properly when we were at shared hosting. Also, all the pages which have ScriptManager is not rendering properly.

We vested almost a day, but no clue as most of our pages were not displaying properly.

See the link about the solution:ASP Menu is not working on Page with ScriptManager

After adding <pages controlrenderingcompatibilityversion="3.5">
in web.config most of other pages came back to normal but the pages with ScriptManager on it was still creating issue.

After looking at all the places, we started looking at IIS to see if we have some setup their which is doing this and we found that "Handler Mappings" or web site was using all the handlers from Plesk and we were not sure what they are doing, so we just went to the IIS -> Sites -> Our Domain -> Handlers Mapping and Took Revert to Parent from the Tools.

And guess what, all the pages returned to normal. I know there must be some other way other than removing all Plesk handler but as we do not know, we just reverted back to standard handler and it worked for us.

Reader, please comment is you knwo any better solution for this.

Happy coding!!

Resolved: Mailbox unavailable. The server response was: Requested action not taken: mailbox unavailable or not local

We have bought Virtual Dedicated Server from Godaddy and migrated all our shared hosted domains to it. We have started getting "Mailbox unavailable. The server response was: Requested action not taken: mailbox unavailable or not local" for almost all the ASP.NET pages which were sending emails from the page.

When we change the relay server to "yourmailserver.secureserver.net" or "mail.yourdomain.com" or "relay-hosting.secureserver.net" or "smtp.secureserver.net", we were nit getting any error but we were not getting the emails.

After inspecting we found two issues.
1. we should supply the relay server either as "localhost" or the one which is provided at the VDS setting screen(Login to GoDaddy -> My Accounts -> My Products -> Servers -> Launch ).
2. The to mail address should be one which is a valid email address. Earlier we were using a any email address, even the email id was not available, because our main address was set with "catch all" option, we were able to get, but with VDS, it was not.

public static void sendHTMLEmail(String emFrom, String emTo, String emSubject, String emBody)
{
            MailMessage m = new MailMessage();
            m.From = new MailAddress(emFrom);
            string[] emailTo = emTo.Split(';');
            for (int i = 0; i < emailTo.Length; i++)
            {
                m.To.Add(emailTo[i]);
            }
            m.Subject = emSubject;
            m.Body = emBody;
            m.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = CredentialCache.DefaultNetworkCredentials;

            smtp.Send(m);

            m.Dispose();

        }

In the web.config, please add following just before   <system.web>


  <system.net>
  <mailSettings>
    <smtp>
      <network host="localhost" />
  </smtp>
    </mailSettings>
  </system.net>


Happy Coding!!

Tuesday, 19 July 2011

ASP Menu is not rendering Properly with ScriptManger

Hi,

Recently I have bought a Virtual Dedicated Server from GoDaddy and migrated all my shared hosted sites to my new Virtual Dedicated Server. The VDS has Windows 2008 R2 Standard installed.

My issue started, with the application, which is using Master Pages and ASP Menu. One of my page is using ScriptManager to call to Webservice function using Ajax. All other pages were running properly, but when we go to this page, all my menu formatting was going bad. The ASP menu was behaving very strange.

Wasted more that 6 hrs in researching on Google and trying all possible combination, but no luck. I started thinking that I have done very big mistake as I was not able to resolve the issue.

Finally I was looking at the web.config file and when compared it with one of the older web.config file from a different application, I found that my file is missing one line, and guess what, adding one line resolve all the issue.

just added
<pages controlrenderingcompatibilityversion="3.5">
So funny.

Please visit : JavaScript is not calling Ajax Local Web Service

Happy Coding!!

Friday, 8 July 2011

Sending mail from SQL Server 2005 with attachment

Please read following to know how to setup and send emails from SQL Server using Database mail feature of SQL Server.
The above feature looks so great to me and I started using same for all my projects. With one of my project, I had to send the output of my SQL Query as an attachment to the email. And I was kind of confuse is it possible from SQL Server? Where can I keep my temporary file which can store the query output and which I have to attach with the mail.

Again I turned to Google God and you now, after researching little bit, I got the solution, and the solution was very very simple. Just few lines of the code and problem is solved. Use following code to send email from SQL Server with attachment.


I am using SQL Server from more that 10 years, but now I am falling in love with SQL Server.

Happy Coding!!

Script to generate CSV file from SQL Server 2005

Many times as a programmer we have to generate .csv or .txt file with the SQL table values. I have done so many times, but all the time I used .NET programming, typically created a DataTable with the table values and used System.IO to write the csv file.

Recently for a new project, I had to do the same. But this time I thought why not do something different, why not search for option in SQL Server which can directly generate the text or csv file from stored procedure. And guess what it is very easy from the SQL Server 2005.

I have used bcp. Please follow the following step to do so.

As bcp is a command line utility, we need to use xp_cmdshell in Stored Procedure to call bcp. But by default the "xp_cmdshell" utility is blocked by the SQL Server. to allow SQL Server to execute "xp_cmdshell", please execute the following with admin account.

You are set once you are done with above. Execute the following to create the csv file.

Happy Coding!!

Sending email from SQL Server 2005

For one of my project we need to send the email from a stored procedure. When I researched little bit on this topic, I come to know about database mail. This is very nice and perfect utility provided with SQL Server 2005.

To send mails thru SQL Server is just few step work.

The first step is to setup the SQL Server Database mail feature. Please follow the following steps to do so.



Database mail is not setup. Use following to send email

Simple, is not it?

Happy coding!!

SOLVED: How do i turn on sp_send_dbmail in SQL Server 2005

Recently I was trying to send mail thru SQL Server 2005. To send mail thru SQL Server 2005, you can use Database Mail options. But when I was trying to send the Email using msdb.dbo.sp_send_dbmail, I was getting "SQL Server blocked access to procedure 'dbo.sp_send_dbmail'".

This is because by default SQL Server block the access of sp_send_dbmail call. To allow SQL Server to send email, please use following command
Happy Coding!!