Archive

Archive for the ‘Bugs’ Category

Log4net integration

January 13, 2017 Leave a comment

Hi folks,
I was integarting log4net library which is amazing for logging in .net Applications.

One issue i run into worth mentioning, I got following error
“log4net:ERROR Failed to find configuration section ‘log4net’ in the application’s .config file. Check your .config file for the and elements. The configuration section should look like: <section name="log4net""

When I used following declartion , issue resolved:

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Regards

Advertisements
Categories: ASP.net C#, Bugs, tricks

Store and Reading connection string in web.config

August 14, 2015 Leave a comment

Handy Tips for freshers:
Connection string in .NET 3.5 (and above) config file:
Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.

<add name="myConnectionString" connectionString="server=\SQLEXPRESS;database=myDb;uid=myUser;password=myPass;" />

To read/access the connection string into your code, use the ConfigurationManager class.
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

Always store the connection string in a config file.
I saw many freshers save connection string on page(Hard Coding) or in session, Never be among them.

Connection string in .NET 2.0 config file
In the appSettings location, add a key named whatever you like to reference your connection string to.


To read the connection string from code, use the ConfigurationSettings class.
string connStr = ConfigurationSettings.AppSettings("myConnectionString");

Hope this will help few!

Ref: https://www.connectionstrings.com/store-connection-string-in-webconfig/

Best Antivirus for Windows in India

August 30, 2012 1 comment

Hi All,
I usually get many queries from my non-techie friends regarding which is best antivirus for Home PC(Here best means good performance & Economical πŸ™‚ ).
In last 10 years I used many antivirus ranging from free to paid.(even pirated,so cannot tell exact which one πŸ™‚ )
Personally I found “Kaspersky Internet Security” is the best, you need to take regular updates(so need to have Internet connection also). Its cost is also very less (around 400-500 Rs/year). Its also light weight so does not slow down your PC.
Note: Kaspersky has three version of the antivirus,so while purchasing check the name.I checked all the three versions specification, and found “Kaspersky Internet Security” is the best version.
I found Norton is also very good,but its heavy, so may slow down your PC.
In free antivirus category,I can recommend AVAST(If you don’t want to pay anything extra fro antivirus or you don’t use internet).
I did some google also before buying the antirus.Just listing them for your reference.
Latest(2012)
Blog Discussion
Old Survey(2009)

Session Funda in PHP

March 5, 2010 Leave a comment

Hey guys,
It took me some time to understand basics of Session in php.
If you create a logout.php to end user session, the right sequence is as follows

session_start();
session_unset();
session_destroy();

he difference between both session_unset and session_destroy is as follows:

session_unset just clears out the sesison for usage. The session is still on the users computer. Note that by using session_unset, the variable still exists.

Using session_unset in tandem with session_destroy however, is a much more effective means of actually clearing out data. As stated in the example above, this works very well, cross browser:

session_unset();
session_destroy();

I noticed that in firefox, one could simply use sesison_unset and the session would be cleared. When trying this on IE, I was horrified to find out that the data was still there, so I had to use session destroy.
(Ref : http://www.php.net/manual/en/function.session-unset.php)

session_unset() is like doing a session_unregister() on all registered variables. They can still be re-registered by calling session_register() whereas after session_destroy, they cannot.

If you want to clear all sessions:
$_SESSION = array();

Categories: Bugs, PHP, tricks

Problem while Sending mail through PHP

March 5, 2010 1 comment

Guys,
Today i faced one problem while sending mail to mail account residing on my server.
I went through the link and found the solution.

The tag at the end of mail() function :
“-femail@domain.com”
ie. mail($sendto,$subject,$message,$headers,”-femail@domain.com”);
works great.
This is a sendmail command line flag. You can use -f to set the sender (“envelope from”) address. The PHP mail() function takes five parameters, including two optional ones that follow the three required ones you’re probably used to.

Categories: Bugs, PHP

Increase PHP memory limit

December 9, 2009 Leave a comment

Hey,

I got error Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 13050 bytes) in my file /home/developer/Sachin/API/performance.php on line 227
You can view memory limit using

1. If your memory is set to 8M, continue with next step
2. Open your php.ini file. If your server is a Webune Dedicated Server with Redhat, Centos or Fedora, you can run the following command to edit the php.ini file:
3. VIM /etc/php.ini (you can view its location in phpinfo())
4. Code:
memory_limit = 64M ; Maximum amount of memory a script may consume (6MB)
5. Save the changes.
6. Restart Apache Server with the following command
Code:
/etc/init.d/httpd restart
7. Done

or
Youcan set the memory limit within a file using ini_set() function:
at ini_set(‘memory_limit’, ’64m’); in your php page.

Categories: Bugs, mysql, PHP

Problems while setting the Cookie

November 14, 2007 Leave a comment

Hi,

Today i faced one problem while setting the COOKIE. We should not echo or output(e.g.while integrating with html) before calling setcookie() function.The Cookie will not be set in this case.So take care will integrating HTML with PHP (especially without using SMARTY)
If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.

Categories: Bugs