Friday, December 30, 2011

Attach database failed : "Unable to open the physical file "....". Operation system error 5: "5(Access is Denied)". Microsoft SQL Server, Error: 5120)

If you receive this follow error while you are trying to attach you old or back-up database mdf file to your Microsoft SQL Server 2008, you can fix it by using the methods mentioned below.

Attach database failed .................
"Unable to open the physical file "....". Operation system error 5: "5(Access is Denied)". Microsoft SQL Server, Error: 5120)

There are several ways of fixing it. I looked for the solutions and found these 3 methods from http://blog.sqlauthority.com. Here, I am going to re-share them again.


Method 1. ----- Tested
CREATE DATABASE ygnonline ON
(FILENAME = N'D:\MyProjects\myapps\database\mydb_Data.mdf')
FOR ATTACH_REBUILD_LOG
GO
***The log file (.ldf) will be recreated.

Method 2.

EXEC sp_attach_single_file_db @dbname='TestDb',
@physname=N'D:\MyProjects\myapps\database\mydb_Data.mdf'
GO


Method 3.

CREATE DATABASE ygnonline ON
(FILENAME = N'D:\MyProjects\myapps\database\mydb_Data.mdf')
FOR ATTACH
GO


I never try myself on method 2 and 3 since the issue I have is fixed with the method 1. Please kindly be advised to check with your database expert before using above methods in live or production environment.
You can also go and read TechNet library of Microsoft for more details in this.
Wish you guys can fix all the bugs you got before coming of the new year!!! Good Luck!! Enjoy!!! All the best!!!!!!

Wednesday, December 28, 2011

PHP Fatal error : Cannot break/continue 1 level

Because you are using break without "switch...case" or looping. You can solve this by changing "break" to "return" to exit from the function.

Enjoy!!! .. all the best... :)

Monday, December 26, 2011

Where does MySQL database stored its data in my harddisk?

Where does MySQL database stored its data in my harddisk?

It depends on where you want it to be stored. Normally you can find the location of your mysql data files in this following config file.

C:\Program Files\MySQL\MySQL Server 5.1\my.ini

If you are using XAMPP, you can find it in here :

D:\xampp\mysql\bin\my.ini

But you may not need to look into that file since you can find your data files in this follow directory.

D:\xampp\mysql\data


Enjoy!! Thanks...
"Correct my if i am wrong by leaving comments down there" :D

Sunday, December 25, 2011

Keyboard shortcuts for Windows


Most of you guys may already have known this combination of this shortcut key on Windows Platform.
I would like to share with you guys about some of the common keyboard shortcuts for windows
Windows Key(windows logo) + M : Minimize all windows 
Windows Key(windows logo) + Shift +M : Undo minimize all windows
Windows Key(windows logo) + F : Open search dialog box to search or find files or folders in your entire computer or your specified area of your computer.
Windows Key(windows logo) + Break : Open system properties window
Windows Key(windows logo) + L : Lock your computer or log off from your windows
Windows Key(windows logo) + Tab : Cycling windows

Ctrl + ESC: Opens the Start menu (use the ARROW keys to select an item)
Ctrl + Tab : Switch between tabs or child windows which are opening in the same windows
Ctrl + T : Redo last done action (it is only available for some applications)



Friday, December 23, 2011

MySQL : "The user specified as a definer ('root'@'%') does not exist"

If you've found following error while using mysql database:
The user specified as a definer ('root'@'%') does not exist
Then you can solve it by using following :
grant all on *.* to 'root'@'%' identified by 'password' with grant option;

Wednesday, December 21, 2011

Using Flexigrid with PHP and MySQL

Flexigrid is a lightweight but rich data grid with resizable columns and a scrolling data to match the headers, plus an ability to connect to an xml based data source using Ajax to load the content.
Features :

  • Resizable columns
  • Resizable height and width
  • Sortable column headers
  • Cool theme
  • Can convert an ordinary table
  • Ability to connect to an ajax data source (XML and JSON[new])
  • Paging
  • Show/hide columns
  • Toolbar (new)
  • Search (new)
  • Accessible API

There are two formats you can get your data return to your page, in JSON or XML.

Follow this link, you can find a sample source code for returning in XML format, and for returning in JSON, follow here.

How it  works:
First, you have to these three lines to your html page

<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.css"> 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> 

Please make sure that you add  <script type="text/javascript" src="jquery.js"></script>  before <script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> since it is using jquery to populate its grid.

then you can add the table definition which you want to show in your web page.
In this following example, the data will display in "flex1" table. 
And the data will be processing in post2.php file and return to your html page in JSON format.

<table id="flex1" style="display:none"></table> 
<script type="text/javascript"> 
$("#flex1").flexigrid({ 
        url: 'post2.php', 
        dataType: 'json', 
        colModel : [ 
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
                ], 
        searchitems : [ 
                {display: 'ISO', name : 'iso'}, 
                {display: 'Name', name : 'name', isdefault: true} 
                ], 
        sortname: "iso", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Countries', 
        useRp: true, 
        rp: 15, 
        showTableToggleBtn: true, 
        width: 700, 
        onSubmit: addFormData, 
        height: 200 
}); 

To get to the point here, please follow below steps to use Flexigrid in your webpage (in php or any languages) with MySQL or any databases.
Let's assume that you already had jquery.js in your root directory.
Step 1:
<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.css"> 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> 

Step 2:
<table id="flex1" style="display:none"></table> 
<script type="text/javascript"> 
$("#flex1").flexigrid({ 
        url: 'post2.php', 
        dataType: 'json', 
        colModel : [ 
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
                ], 
        searchitems : [ 
                {display: 'ISO', name : 'iso'}, 
                {display: 'Name', name : 'name', isdefault: true} 
                ], 
        sortname: "iso", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Countries', 
        useRp: true, 
        rp: 15, 
        showTableToggleBtn: true, 
        width: 700, 
        onSubmit: addFormData, 
        height: 200 
}); 

**if you want to use xml, just replace
dataType: 'json' with datatype:'xml'.

Steps 3: Create the processing page in php or any language you like.
Here is the sample pages in php format. please find json and xml

You can use $("#flex1").flexReload(); to reload or refresh your flexigrid. But you have to put it in right location in order to use it effectively.

And you can find full sample source codes for flexigrid at https://code.google.com/p/flexigrid/source/browse/#svn%2Ftrunk%2Fdemo

Download flexigrid directly here. or go to flexigrid.info for more detail.

Be remind yourself not to forget ; semi-colon and cases since both javascript and php are case-sensitive scripting engines.

All the best!!! Enjoy!!!



Sunday, December 18, 2011

Binding data to dropdown list with php from mysql database

This is just a basic for some of you guys. But if you are new to it, it will take some times for you to figure it out. So, please follow the steps mentioned below, and you will get there in no time.

<select name="yourselection">
    <option value="">--Select--</option>
    <?php
$msql = mysql_query("SELECT * FROM manufacturer");
while($m_row = mysql_fetch_array($msql))        
        echo("<option value = '" . $m_row['m_code'] . "'>" . $m_row['m_name'] . "</option>");
  ?>
</select>

Thursday, December 15, 2011

Create multiple virtual hosts in Apache/XAMPP

I am working with both IIS and Apache, so I assigned port number 9000 to apache web server. You may change as you wish.

Step 1: Please modify your httpd.vhosts as follows :
It is locating under D:\xampp\apache\conf\extra

NameVirtualHost *:9000



<VirtualHost *:9000>
ServerAdmin webmaster@localhost
DocumentRoot D:\YourSite
ServerName yoursite


<Directory "D:\YourSite">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:9000>
ServerAdmin webmaster@localhost
DocumentRoot D:\YourSite1
ServerName yoursite1


<Directory "D:\YourSite1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


<VirtualHost *:9000>
ServerAdmin webmaster@localhost
DocumentRoot D:\xampp\htdocs
ServerName localhost


<Directory "D:\xampp\htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Step 2:
Open your notepad with administrator permission, then go to C:\Windows\System32\drivers\etc


and Open that file called hosts and add your virtual hosts as follows

127.0.0.1 yoursite
127.0.0.1 yoursite1

You don't need to add your localhost. 

Now, you can browse your sites as follows

http://yoursite:9000 which will get you to your site hosted on your apache web server.
http://yoursite1:9000 which will get you to your site1.


If you want to go to your xampp page, just browse like http://localhost:9000, then it will get you to this:

And finally you can get to Microsoft IIS by typing http://localhost in your browser's address bar and go.

If you think there is some mistakes in my post, please leave a comment. Thanks.
Enjoy!!! 

Saturday, December 10, 2011

Remove or delete duplicate records or rows from SQL Server Database.

You can delete or remove the duplicate records or rows from your SQL Database Table without needing identical column with following piece of code. I used single field or column in this example. If you have better solution, please kindly leave a comment. 



SELECT * INTO #TempTable FROM DTABLE GROUP BY DRECORD HAVING COUNT(DRecord)>1
DELETE FROM DTABLE
INSERT INTO DTABLE SELECT * FROM #TEMPTABLE
DROP TABLE #TEMPTABLE
SELECT * FROM DTABLE

















All the best!!!!

Thursday, December 8, 2011

How to fix: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path.

When you are getting the following error on your shared hosting server.


Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.


You can fix it by following steps

1. Open your local data file "ASPNETDB.MDF" from you visual studio's solution explorer.
2. Right click on "ASPNETDB.MDF" and click "Publish to Provider"
3. "Script to file"
4. Click "next" or "finish" to create a script file.
5. Open the generated script file in your database's query window.
6. Make your the selected database is your main database to use.
7. Execute the script.
8. You will see asp.net application services tables in your database which are the tables with "aspnet_" prefix.
9. Change your connection string "ApplicationServices" as mention below
<add name="ApplicationServices" connectionString="Data Source=XXPC\sqlexpress;Initial Catalog=yourdb;Persist Security Info=True;User ID=sa;Password=1234;" providerName="System.Data.SqlClient" />


Now your application's membership services and user profile will be working with the database from your sql server and no more with local data file.

SQL Management 2008 Error: "Saving changes is not permitted."

Are you getting this error message when you are trying to change any of the information on your table(s) in you database??

Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.


You can fix this by following action.



Go to #Tools# -> #Options# -> #Designers# -> #Table and Database Designers# and uncheck the Prevent saving changes that require table re-creation checkbox.

Login failed for user IIS APPPOOL\DefaultAppPool

ASPNETDB.MDF!!!. I have been trying to use this ready-made login system from .net framework 4.0. In stead, I have got trapped in the middle of nowhere for a couple of days.


ASPNETDB.MDF, a database file, which is automatically created by .net framework when you created a ASP.NET web application by selecting ASP.NET Web Application not ASP.NET Empty Web Application (fig 1).


The new WebApplication1 came with its pre-created login and register page. You don't need any code for user registration and login process.


There will be no problem until you try to browse your website directly from web browser.
You will face this following error when you browse your website via web browser

"Login failed for user IIS APPPOOL\DefaultAppPool"

When you get this error, you can solve this by adding IUSR to your APP_Data folder's permission in your wwwroot or your website root folder.
You can also fix by transfer your tables and data from ASPNETDB.MDF to your application's sql database, and then you can change your connection string to point to new location of application services data tables.

But for the production site, there will be a different story.

You can find detail information about this issue at http://support.microsoft.com/?kbid=2002980.
It seems that I have to ask my hosting provider to add write permission on my application App_Data folder which is I am not comfortable to do.