Visual Studio 2013 - execute Model.edmx.sql trough MySQL? - mysql

I'm learning the way ADO.NET Models works in Entity Framework with MySQL. I Generate new test model and then select "Generate Database from model"
It produce for me new file "model_name.edms.sql" - actual MySQL script for database creation.
However to execute it I have to "Connect to Server" which by default comes as SQL Server 2012. but in my case I use MySQL and not MS SQL Server. I dont have SQL12 instance, im working with MySQL
How do I change it to connect to MySQL?
P.S. I know I can use "New Query" directly on database and copy / paste content of the file and execute. also I can use MySQL Workbench and tons of other applications, however im working in VS2013 where most of the tools already integrated, I cant believe that SQL files in VS13 can be executed only trough MS SQL12

I've just ran into the same problem and that's how to solve it.
I'm using VS 2010 Ultimate but I guess it's the same in VS 2013.
First, when you connect (and execute the sql) from the toolbar you actually request to do it on the 'Transact-SQL Editor' toolbar, which means that the toolbar handles the MS databases. That's why you ALWAYS get a connection dialog to MS databases.
If MySQL package is properly installed in VS (and apparently that's the case for you) you should:
Right click any existing toolbar (or go to View->Toolbars) and select MySQL. This should add the MySql Toolbar.
Click on the first button from the left (in 'MySQL Toolbar') to either connect to an existing Data Connection or create a new connection to your MySql DB. A MySql script tab will be added.
Copy all the sql generated from the EDMX file to the 'MySql script tab'.
Run the script from the 'MySql script tab'.
That should do it.
I know there's still a little copy-paste involved but at least you don't have to leave VS.
Hope that helps
cheerio

First, you have to be sure that you have downloaded MySQL for Visual Studio. This is NOT Connector/Net (though you should probably have that, too).
In VS, when you open Server Explorer, you should be able to add a database. Input your server name, user name, password, and don't forget to click the Advanced button and add in your port (usually 3306). All of this information can be obtained from your MySQL Workbench. Now you should be able to deploy your EDMX to your MySQL database using the same steps you would use for SQL Server.
Full steps from Oracle can be found at http://dev.mysql.com/doc/connector-net/en/connector-net-visual-studio-making-a-connection.html.
EDIT: Once you've performed the steps above, right-click in a blank space of your EDMX and choose SSDLToMySQL.tt in the dropdown on the DDL Generation Template. SSDLToSQL[version].tt is the default choice.

If you rename the whatever.edmx.sql file to whatever.edmx.mysql it will open in the proper tool and allow you to connect to your MySQL database server and run the script.
Perhaps at some point the generator will be updated to create the EDMX file with the ".mysql" instead of the ".sql" file extension to begin with.

Related

Creating custom MySQL servers in VB.NET at runtime

I was wondering if it is possible to create custom MySQL servers in VB.NET while working in visual studio at runtime so that if the server already exists it connects and if it isn't there, the code creates the server. I have searched for this everywhere but couldn't find anything. I would appreciate it a lot if someone guides me to the right path.
You could certainly write some .net code to start a MySQL server on your Windows box when an attempt to connect fails. You simply get a cmd.exe console with administrator privileges and give the command net start mysql.
But MySQL must already be installed on the box for that to work.
You might investigate Sqlite. It provides SQL locally to a .net program, storing your tables in a file called whatever.db. It has very similar .net API access to MySQL's Connector/Net and SQL Server's connector. It's in a NuGet package.
I don't completely understand your "custom MySQL servers" requirement. Sqlite gives you a way to use SQL in your application without connecting to a shared server. That may do what you need.
MySQL does have a CREATE SERVER statement in its SQL dialect. The purpose of this statement is to create a connection to another, remote, MySQL server. With that connection you can use the FEDERATED storage engine to access tables in the remote server. Of course, there is no way to run this CREATE SERVER statement unless your program is already connected to a MySQL server.
With respect, your "task which states to create a server at runtime" doesn't make much sense. Is there more to this requirement? What workflow needs this step? Is it part of the installation of some application software on a new box?

Can we restore database backup of SQL Server 2008 R2 Express to SQL Server 2008 Express

I have a database backup in "SQL Server 2008 R2", Can i store this database backup in "SQL 2008 Express" ?
Anyone who have knowledge about SQL-2008 kindly share to me.
No and 'yes'.
A backup (.bak) is not possible, nor is copying .mdf over but you can downgrade.
You could go back to 2005 if you wish to.
I found this information which runs you through it the easy way.
How to Downgrade SQL Server Database
Direct link: http://www.mytechmantra.com/LearnSQLServer/Downgrade_SQL_Server_Database_P1.html
TIP: Use Microsoft OLEDB connector to destination instead of the native client and you should avoid any errors in the transfer
Nothing is impossible, you just have to get creative :)
Install an instance of SQL 2008 R2 on one machine and SQL 2008 on another
Open SQL Server Management Studio R2
Select your source Database
Select Tasks>Generate Scripts.
Select 'Script entire database and all database objects', press 'Next'
Select 'Save to File' and click on the 'Advanced' button
Select 'Script for Server Version' and select the version you want: 200/2005/2008
Select 'Type of data to Script' and select Schema/Data/both
Click 'OK',Next and do it!
Copy the resulting file to the target machine with SQL 2008 [or whatever]
Log onto your SQL Management Studio and open the copied .sql file... be aware that there may be limitations on the file size.
There may also be issues with the order that the .SQL file inserts the data into the target database and if there are FK constraints in place, this could be an issue.... simply re-order the insert lists.
Once the .sql file is organized, parse it [just to sure], and then execute.
Let me clarify a little on these directions.
On the SQL Management Tools be logged into both the old and the new server if possible.This makes these steps even easier.
So, start with the source server, right click on the database and script it. There is one option called ‘Script Data’ that is off by default, we set it to true so the script will include inserts for all of the data. We choose to script the tables, views, indexes and keys (and triggers … not sure if you use any of those). I also did not mess with the users, since that is problematic. It is easier to create the user by hand once on the local SQL server and give them permissions to the dbs.
Then script the DB to a file.
Then select the local SQL server and add the database by hand, then open up the script file and execute it under the new database, all the tables, data, indexes, etc came over just fine. Setup the user permission and you are golden.
NO, you cannot do this.
There is no way, no method, no hack, no workaround, no trick to get a backup from a more recent version of SQL Server back into an older version.
It just doesn't work - it's not supported.
You'll need to synchronize your structure using some kind of SQL diff tool, and possibly your data by exporting and importing, e.g. via the "Data Export / Import" wizard or some custom way.

Downgrade mdf file from 661 to 655

I created and database in sql server 2008. I took the mdf and ldf files to Visual Studio 2010 project and tried to connect to that db with entity-framework. and got the following message:
I cannot reinstall or upgrade the software on the specific computer.
So is there any way to downgrade the version of the mdf and ldf files?
No, you cannot downgrade, you will need to move the schema and data another way if you can't install the right version. This recent question is essentially the same:
Failure attaching SQL Server 2008 database to SQL Server 2005
Essentially you can use the Generate Scripts tool or the Export Data wizard to get your destination database to look like the source. You will not be able attach your MDF file.
And this blog post shows some 3rd party tools that can help with this:
http://bertrandaaron.wordpress.com/2012/04/20/re-blog-the-cost-of-reinventing-the-wheel/
No, you need to install the same or newer version of SqlServer.
There is no known way to downgrade an MDF file.
Links
http://blog.sqlauthority.com/2008/10/16/sql-server-downgrade-database-to-previous-version/
Perhaps, if you have access to the SqlServer 2008, you could use the command
"Tasks" -> "Create Scripts" to start the wizard to create a script with schema and data.
On the options page there is the button 'Advanced' where you can select the syntax version of SqlServer
The way that I found that worked was to export the database and stored procedures from the original database. Then upload them into the second database(second computer).
Firstly export the DB content (data) - I used SQL server export data wizard. on the database you wish to export from right click then choose tasks, then export data. Follow the instructions and save in whichever format is best for you - I used excel for the data.
then to export the stored procedures rightclick the database name again. choose tasks and this time choose generate scripts. again follow the instructions of the wizard.
To import the data simply go to the second computer and right click the database you wish to import the data into. again tasks > import data. Follow the instructions to import all of the data from the database.
Finally to import the stored procedures, I opened up a new stored procedures command and dragged and dropped the script file that I had previously saved them in and dropped it into this window. The new stored procedure window filled with the entire list of my stored procedures.
Finally change the name of the database name that will be used by the SP ( if this is different from the original DB name). (This is the first line USE [DBName].
then simply execute and the SP's will be fully restored.
This has helped me get my entire database up and running again very quickly.
Hope this helps.
U can open it on another pic and then publish it to sql script with or without data then create database on target PC using sqlcmd or anything. Then run sql script...

What steps are needed to use an Entity Framework model with a MySQL server?

I've added and designed an ADO.NET Entity Data Model (.edmx) and have generated the corresponding DDL Script (.edmx.sql). When I was using SQL Server 2008, all I had to do was connect to it via the Transact-SQL Editor toolbar and execute the SQL. When I try this method, however, it doesn't let me connect to the MySQL server, as it seems to be looking only for Microsoft SQL Servers. I have the latest version of Connector/Net, and can add the MySQL database as a Data Connection, but cannot execute the script I need. What steps are needed to use an Entity Framework model with my MySQL server?
I stumbled across this little property while editing my Data Model:
(This option was installed along side Connector/Net.)
After changing to SSDLToMySQL.tt, right-click and select Generate Database from Model... as you would normally. This will generate the .edmx.sql file, and should give you several errors (as .NET uses SQL Server to parse .sql files.) After generating the DDL script, I opened up MySQL Workbench and pasted the script in. You need to make sure that an appropriately-named schema already exists on the server, then run the script, and voila.

How to import a SQL Server .bak file into MySQL?

The title is self explanatory. Is there a way of directly doing such kind of importing?
The .BAK files from SQL server are in Microsoft Tape Format (MTF) ref: http://www.fpns.net/willy/msbackup.htm
The bak file will probably contain the LDF and MDF files that SQL server uses to store the database.
You will need to use SQL server to extract these. SQL Server Express is free and will do the job.
So, install SQL Server Express edition, and open the SQL Server Powershell. There execute sqlcmd -S <COMPUTERNAME>\SQLExpress (whilst logged in as administrator)
then issue the following command.
restore filelistonly from disk='c:\temp\mydbName-2009-09-29-v10.bak';
GO
This will list the contents of the backup - what you need is the first fields that tell you the logical names - one will be the actual database and the other the log file.
RESTORE DATABASE mydbName FROM disk='c:\temp\mydbName-2009-09-29-v10.bak'
WITH
MOVE 'mydbName' TO 'c:\temp\mydbName_data.mdf',
MOVE 'mydbName_log' TO 'c:\temp\mydbName_data.ldf';
GO
At this point you have extracted the database - then install Microsoft's "Sql Web Data Administrator". together with this export tool and you will have an SQL script that contains the database.
MySql have an application to import db from microsoft sql.
Steps:
Open MySql Workbench
Click on "Database Migration" (if it do not appear you have to install it from MySql update)
Follow the Migration Task List using the simple Wizard.
I did not manage to find a way to do it directly.
Instead I imported the bak file into SQL Server 2008 Express, and then used MySQL Migration Toolkit.
Worked like a charm!
In this problem, the answer is not updated in a timely. So it's happy to say that in 2020 Migrating to MsSQL into MySQL is that much easy. An online converter like RebaseData will do your job with one click. You can just upload your .bak file which is from MsSQL and convert it into .sql format which is readable to MySQL.
Additional note: This can not only convert your .bak files but also this site is for all types of Database migrations that you want.
Although my MySQL background is limited, I don't think you have much luck doing that. However, you should be able to migrate over all of your data by restoring the db to a MSSQL server, then creating a SSIS or DTS package to send your tables and data to the MySQL server.
hope this helps
I highly doubt it. You might want to use DTS/SSIS to do this as Levi says. One think that you might want to do is start the process without actually importing the data. Just do enough to get the basic table structures together. Then you are going to want to change around the resulting table structure, because whatever structure tat will likely be created will be shaky at best.
You might also have to take this a step further and create a staging area that takes in all the data first n a string (varchar) form. Then you can create a script that does validation and conversion to get it into the "real" database, because the two databases don't always work well together, especially when dealing with dates.
The method I used included part of Richard Harrison's method:
So, install SQL Server 2008 Express
edition,
This requires the download of the Web Platform Installer "wpilauncher_n.exe"
Once you have this installed click on the database selection ( you are also required to download Frameworks and Runtimes)
After instalation go to the windows command prompt and:
use sqlcmd -S \SQLExpress (whilst
logged in as administrator)
then issue the following command.
restore filelistonly from
disk='c:\temp\mydbName-2009-09-29-v10.bak';
GO This will list the contents of the
backup - what you need is the first
fields that tell you the logical names
- one will be the actual database and the other the log file.
RESTORE DATABASE mydbName FROM
disk='c:\temp\mydbName-2009-09-29-v10.bak' WITH MOVE 'mydbName' TO
'c:\temp\mydbName_data.mdf', MOVE
'mydbName_log' TO
'c:\temp\mydbName_data.ldf'; GO
I fired up Web Platform Installer and from the what's new tab I installed SQL Server Management Studio and browsed the db to make sure the data was there...
At that point i tried the tool included with MSSQL "SQL Import and Export Wizard" but the result of the csv dump only included the column names...
So instead I just exported results of queries like "select * from users" from the SQL Server Management Studio
SQL Server databases are very Microsoft proprietary. Two options I can think of are:
Dump the database in CSV, XML or similar format that you'd then load into MySQL.
Setup ODBC connection to MySQL and then using DTS transport the data. As Charles Graham has suggested, you may need to build the tables before doing this. But that's as easy as a cut and paste from SQL Enterprise Manager windows to the corresponding MySQL window.
For those attempting Richard's solution above, here are some additional information that might help navigate common errors:
1) When running restore filelistonly you may get Operating system error 5(Access is denied). If that's the case, open SQL Server Configuration Manager and change the login for SQLEXPRESS to a user that has local write privileges.
2) #"This will list the contents of the backup - what you need is the first fields that tell you the logical names" - if your file lists more than two headers you will need to also account for what to do with those files in the RESTORE DATABASE command. If you don't indicate what to do with files beyond the database and the log, the system will apparently try to use the attributes listed in the .bak file. Restoring a file from someone else's environment will produce a 'The path has invalid attributes. It needs to be a directory' (as the path in question doesn't exist on your machine).
Simply providing a MOVE statement resolves this problem.
In my case there was a third FTData type file. The MOVE command I added:
MOVE 'mydbName_log' TO 'c:\temp\mydbName_data.ldf',
MOVE 'sysft_...' TO 'c:\temp\other';
in my case I actually had to make a new directory for the third file. Initially I tried to send it to the same folder as the .mdf file but that produced a 'failed to initialize correctly' error on the third FTData file when I executed the restore.
The .bak file from SQL Server is specific to that database dialect, and not compatible with MySQL.
Try using etlalchemy to migrate your SQL Server database into MySQL. It is an open-sourced tool that I created to facilitate easy migrations between different RDBMS's.
Quick installation and examples are provided here on the github page, and a more detailed explanation of the project's origins can be found here.