I would like to copy table definitions from an existing database file into a new lightswitch project, does anyone know how to do that, it seems like you can only create a new database from scratch or attach an external database, but when i try to attach an external mdf file from another VS project I get an error which states: CREATE DATABASE Permission denied in database 'master'.
Any ideas about how to copy the table definitions from an existing database file into a lightswitch project?
If you have the external database attached on an instance of SqlServer, you shouldn't have no problem attaching to it from LightSwitch. From that point on, you can rename tables and columns, change datatypes etc, as well as adding more tables and structures to that DB.
Note that the DB is supposed to be served from a SqlServer instance, not a file on your file system.
As far as I know it can't be done. Lightswitch holds a representation of the database tables separate from the actual database definition. You can probably go the other way however because when the ApplicationDatabase.mdf file does not exist you can start Lightswitch (you will notice the table definitions are still in there) and then build the app which will recreate your ApplicationDatabase.mdf. It is empty of course but If you could find out where lightswitch stores those table definitions (an *.xaml file somewhere?) you might be able to get those copied into your project and then generate the ApplicationDatabase.mdf from there?
Related
I'm busy writing a small app and I only want a database to load small amounts of data, in other words I don't need the functionality of SQL.
So I've installed filehelpers, but it seems very limited in the sense that I can read/write and even append data, but it seem impossible to delete one row of data in a table?
Does anyone know how to do this with filehelpers or point me to a different solution where I can just add a local db to my app without any other external software required?
PS. My visual studio does not have the "create local db" from the item selection.
For something like this, I'd use an embedded SQLite database. It gives you the best of both worlds, one file database for local data and most of the features of SQL.
See here: https://sqlite.org/
On their download page, they have lots of stuff and a plugin for VS:
https://sqlite.org/download.html
So I have created a database in C#, and the mdf is in a specified location also attached to the same server (it is a backup database).
Now I want to know how to copy all the tables together with its data, definitions, and stored procedures from one table to the newly created one. Basically, they would be the same database with a different name and will be stored in a different location. I don't intend to use .bak by the way if someone suggests it.
Will I be able to do this in a query? or better yet, in C#? Or maybe I'm doing this wrong. Any suggestions will be welcome with open arms.
Summary
With Sql Server Management Studio (SSMS) you can right click on your database, select tasks, then generate scripts. This will bring up a wizard. In the Choose Objects step, you can select a radio button that will allow you to select your database tables individually. The next step Set Scripting Options will give you the ability to create a script in a single file, a file per object (table, sproc, etc). At this point you can click next through the rest of the wizard or review the steps.
If you use a script file, this can be used to recreate your database. Just modify the USE [YourDbNameHere].
Reference
https://msdn.microsoft.com/en-us/library/hh245282.aspx
I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options:
Local Database
Service-based Database
All I want is a simple local database to use for my project.
However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class creator it says:
The selected object(s) use an unsupported data provider.
So, I don't know why creating a local database would be considered an unsupported provider when dragging to tables to the Object Relational designer.
So, I try the second type, "Service-based Database". I lay out my tables how I want for my basic application and make my tables. The LINQ-To-SQL Designer works fine when I drag these tables and I proceed to write my code in my app to insert and upate the database entries.
However, with this second "Service-based Database" my inserts and updates work as long as the application is running. However, once I close it it reverts back to what it was before. If I manually add in data via the Server Explorer it persists but any inserts I do don't save.
Why can't I create and use a Local Database with LINQ?
If that isn't an option, then why isn't the "Service-Based Database" (whatever that is), persisting beyond the application closing?
Thanks for your time!
Edit: Apparently the LINQ-To-SQL Object Designer doesn't work on Compact Edition Local Databases. It can still be done, but you have to use SqlMetal apparently to generate the dmbl file.
When you compile, the old database gets erased and a new one is copied to the bin folder. Therefore try link (using linq) to the database in the bin folder. Try change your connectionString.
I have a question. I have a project that uses an edmx and all hooks up fine to the sql server.
I have installed it in several servers.
What I want to know is, having made changes in development so m database and my edmx are change,s say a new table and a modified one.
How do I make it so these updates are aplied automatically when I publish an app update?
I remember once a long time ago doing code first database work and making some kind of file or procedure that would automatically apply these changes when the app ran.
Can any one fill me in again.
1.- AFAIK, when you're using model first or database first, you can't use Migrations, you generate a DDL script that when executed, creates the database or drops and recreates tables losing any data you had.
See This link read point number 5.
"The script that is generated will drop all existing tables and then recreate the schema from scratch. This may work for local development but is not a viable for pushing changes to a database that has already been deployed. If you need to publish changes to a database that has already been deployed, you will need to edit the script or use a schema compare tool to calculate a migration script."
What I do here, is make the changes to the database and update the model (Right click edmx designer, click "update model from database")
2.- You can configure updates on a ClickOnce installer, any changes made to the edmx will be published on your app.
I'm making a WinForms app in C#. When I go to create my database object, I'm presented with two options:
Local Database
Service-based Database
All I want is a simple local database to use for my project.
However, if I select "Local Database (Compact Edition)" then after I create my tables and drag them over to a LINQ-To-SQL Class creator it says:
The selected object(s) use an unsupported data provider.
So, I don't know why creating a local database would be considered an unsupported provider when dragging to tables to the Object Relational designer.
So, I try the second type, "Service-based Database". I lay out my tables how I want for my basic application and make my tables. The LINQ-To-SQL Designer works fine when I drag these tables and I proceed to write my code in my app to insert and upate the database entries.
However, with this second "Service-based Database" my inserts and updates work as long as the application is running. However, once I close it it reverts back to what it was before. If I manually add in data via the Server Explorer it persists but any inserts I do don't save.
Why can't I create and use a Local Database with LINQ?
If that isn't an option, then why isn't the "Service-Based Database" (whatever that is), persisting beyond the application closing?
Thanks for your time!
Edit: Apparently the LINQ-To-SQL Object Designer doesn't work on Compact Edition Local Databases. It can still be done, but you have to use SqlMetal apparently to generate the dmbl file.
When you compile, the old database gets erased and a new one is copied to the bin folder. Therefore try link (using linq) to the database in the bin folder. Try change your connectionString.