Wednesday, March 9, 2016

Create database for Entity Framework


down voteaccepted
Follow below steps:
1) First go to Server Explorer in Visual Studio, check if the ".mdf" Data Connections for this project are connected, if so, right click and delete.
2 )Go to Solution Explorer, click show All Files icon.
3) Go to App_Data, right click and delete all ".mdf" files for this project.
4) Delete Migrations folder by right click and delete.
5) Go to SQL Server Management Studio, make sure the DB for this project is not there, otherwise delete it.
6) Go to Package Manager Console in Visual Studio and type:
  1. Enable-Migrations -Force
  2. Add-Migration init
  3. Update-Database
7) Run your application
Note: In step 6 part 3, if you get an error "Cannot attach the file...", it is possibly because you didn't delete the database files completely in SQL Server.

if  this error :A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
)
       : sqllocaldb c Projects 11.0
Command line explained
  • c - is for "create"
  • "Projects - is the instance name
  • 11.0 is the version

Monday, February 22, 2016

Wordpress Multiside migration


Moving or migrating a WordPress Multisite can be frustating. If you don't know how to move it safely, your site can break along the way. Either the database, the settings, or both. Let me share you how to migrate WordPress Multisite safely without breaking anything.
In this tutorial, I will explain how to moving WordPress Multisite from live server to localhost with an example case: we will move WordPress Multisite from http://example.com to http://localhost/example.
In this case, the live server is using cPanel and the localhost is running on XAMPP.
  1. First, we have to copy all WordPress files from live server. You can download it all via FTP. Or if you prefer to download it directly from cPanel, you can go to 'File Manager' in your cPanel. Navigate to public_html. Select all files, click 'Compress'. Download the compressed file. Don't forget to delete the compressed file from live server after you finish download it.
  2. Now we need to copy the database. Go to cPanel's phpMyAdmin. Export the entire database of WordPress Multisite that we want to move.
  3. Create new folder 'example' in localhost folder (\xampp\htdocs\). Extract the compressed file that we have downloaded in step 1 to the folder 'example'. Now we have the WordPress files inside the folder 'example'.
  4. Create new database in the local phpMyAdmin. Visit http://localhost/phpmyadmin/. For this tutorial, I will name it 'exampledb'. Import database that we have exported from live site in step 2.
  5. Open .htaccess in the root folder (\xampp\htdocs\example\). Edit RewriteBase into:
    RewriteBase /example/
  6. Open wp-config.php. Change database information to:
    /** The name of the database for WordPress */
    define('DB_NAME', 'exampledb');
    
    /** MySQL database username */
    define('DB_USER', 'root');
    
    /** MySQL database password */
    define('DB_PASSWORD', '');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');
    Also, edit these two lines to:
    /* Multisite */
    
    define('DOMAIN_CURRENT_SITE', 'localhost');
    define('PATH_CURRENT_SITE', '/example/');
  7. After that, we need to change all urls. DO NOT manually search and replace everything. WordPress database use data serialization. Any mistakes can make your site cannot work properly. You have to use tools or scripts to search and replace database. As recommended on WordPress, we will use Search and Replace Database script from interconnectit.com. Download that script (We use V 2.1.0 Stable).
  8. Extract that script's .zip file. You will see .php file inside. For security reason, rename it to difficult name. Something like: w39opzzzzzzzt.php. Make it hard to be guessed!
  9. Copy it to the root folder.
  10. Run the script by visiting http://localhost/example/w39opzzzzzzzt.php (or your choosen file name in step 8).
  11. Check 'Pre-populate the DB values form with the ones used in wp-config? It is possible to edit them later.' Click 'submit'.
  12. Click 'Submit DB details'.
  13. Select all tables. Leave 'Leave GUID column unchanged?' unchecked. Click 'Continue'.
  14. Search for http://example.com, replace with http://localhost/example. Click 'Submit Search string'.
  15. Don't forget to DELETE Search and Replace Database script .php file as soon as you finish use it!! It is very very important for security reason. You don't want someone to use it and break your site, do you? :)
  16. Go to database (http://localhost/phpmyadmin/).
  17. Check wp_site table (or yourtableprefix_site). Change domain, from example.com to localhost. And path, from / to /example/
  18. Also change domain and path in wp_blogs table (or yourtableprefix_blogs).
  19. Now, visit the site in http://localhost/example. You should see it running smoothly without problem. :)