SQL Database running to other computers - sql

I have question about Entity Framework projects or ADO.NET.
How can other users use my project without import SQL database? Is there any method to automatically create database/tables?
Could you please give hints or reference article or something like that.
Thanks,

How can other users use my project without import SQL database?
If you have a project that is just starting a good choise is to use Code First. In this case every developer can use a local database.
Is there any method to automatically create database/tables?
Here comes the good part of Code first - the database will be generated for you. Another thing that helps a lot, in my opinion, is the seeding of test data - Use Code First Migrations to Seed the Database.
Further reading: Migrations

You can use enbedded dbs like derby,h2 etc.

Related

SQL Server - Checkout system for database objects?

I was wondering if anyone knows any 3rd party tools or existing functionality in SQL Server 2008 so that when someone is working on a table or procedure, it is locked out to that individual. I have searched the net extensively and can't seem to find anything relating to this. We are facing a problem where two people may be working on the same stored procedures and whoever executes last gets the code change! This kind of functionality would come in handy. I think that a lock or check in/check out system would be benefit a project, any ideas?
I am already hooked up to Redgate source control, which does not provide this functionality.
Thanks
Try and have a look at this SO discussion: How do I version my SQL Server database in SVN?
It might not lock things like you want, but it would help to ensure code is recoverable. You could also consider using DDL triggers as some kind of a checking mechanism.
you could try this: http://www.apexsql.com/sql_tools_version.aspx
Alternatively, try this: http://www.red-gate.com/products/sql-development/sql-source-control/entrypage/5-minutes?utm_source=google&utm_medium=cpc&utm_content=unmet_need&utm_campaign=sqlsourcecontrol&gclid=CK_qsPC5prUCFe7MtAodzC8ACA

Can Linq to SQL create a database from DDL files?

Is there anything built into the Linq to SQL libraries that allow me to create an entire database from a collection of DDL files?
Lets say you have a collection of DDL files, one for each table in the database. Conceptually it would be pretty straight forward to call a create table function for each one and each one that succeeds (does not through SQL exception for example due to a relationship or foreign key error) pop the file name off the stack. For any that failed you could try to call the DDL again until it finally succeeded and all of your tables existed in the database ... however ... if there is something like this that already existed in say Linq to SQL or the Migrations project that would be great. Does anyone know if this exists already without having to combine all of the DDL's into a single script? Thanks in advance.
If you have Visual Studio 2008 or 2010 Professional or Above, it includes the new version of database projects. Which can handle that precisely for you (it will even validate the scripts before execution so you can see what errors exists).
I don't believe so. Linq-to-Sql is not really made for manipulating database schemas. You might have more luck with something like the Microsoft SMO libraries.
Use ADO.NET commands instead for that. That should be able to handle it, depending how complex each file is. As long as each file has on executable statement, ADO.NET commands may work fine for what you want to do.

FluentNHibernate: Getting the Examples.FirstProject to work

Im trying to get the most basic of examples to run in FnH. I started with the Examples.FirstProject. However, I did not use the SQL lite configuration. Instead, I set the configuration to SQL2005 and created the tables as was diagramed in the example.
When stepping through the code, there appears to be no problems when creating the session factory. I do receive an error however when the code reaches the "transaction.commit" line. The error reads:
Could not insert collection: [Examples.FirstProject.Entities.Store.Products#5][SQL:SQL not available]
Im wondering if there was an issue with the way the tables were created in SQL Server. The IDs were "int" type and the names and such were "varchar(50)." I set the PK of Store, Product, and Employee to its respective ID field. I also made the ID increment automatically by 1 (IdentitySpecification column property in SQL Server). StoreProduct is the many-to-many and is also there per the diagram.
Any help would be appreciated. Thanks.
Have you modified the sample in any way other than changing the database provide? Have you been able to save any entities from the sample (ie if you remove the Products code and just save the Store)?
I developed this sample against SQLExpress, so I would imagine there wouldn't be any incompatibilities with SQL 2005.
Also, this question would probably be better be suited to the Fluent NHibernate mailing list, as Stack Overflow isn't great for these kind-of investigatory postings.
Thank you James. I'll look at using Fluent NHibernate mailing list. As a solution to my issue, I did simplify the example a bit and found that rebuilding the tables helped. In the previous attempt I built the tables in the Database diagram tool. That is where I think something was a little off. Just now I rebuilt them using the menus and still made the foreign key connections with the Database Diagram section. Worked like a charm. Thanks again and keep up the good work with FnH.
First thing to check: Are you sure that you have really created a correct table in SQL server, and that the schema is correct? You can verify this by using SQL Express management studio to view the sql database.

Loading an existing database into WWW SQL Designer?

I've used WWW SQL Designer several times to design databases for applications. I'm now in charge of working on an application with a lot of tables (100+ mysql tables) and I would love to be able to look at the relations between tables in a manner similar to what WWW SQL Designer provides. It seems that it comes with the provisions to hook up to a database and provide a diagram of its structure, but I've not yet been able to figure out exactly how one would do that.
I know this is really old stuff, but I found the solution (if people are looking for it) : you have to edit the file backend/php-mysql/index.php and fill the connection settings. All you need is then to click on Import From DB, and then Load with the name of your database.
function setup_import() {
define("SERVER","localhost");
define("USER","");
define("PASSWORD","");
define("DB","information_schema");
}
http://code.google.com/p/database-diagram/
This takes a SQL structure (SQL dump) and shows a diagram :)
Can you just export the sql query that builds your existing tables, and run that in WWW SQL Designer? Most database management software has that option...
Looking at the interface of the designer, I guess that when you run it on your own PHP/MySQL server, you should be able to import existing database with "Import from DB" button in Save/Load dialog.
You could use VISIO to import the database, it will diagram it for you.
btw, have you tried SchemaBank? They are web-based and support MySQL fairly well. It eats your sql dump and generates the tables and relationships for you.

Best way to version control T-SQL? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Stored procedures/DB schema in source control
What's the best way to version control my tables, views, sprocs, etc? Preferably automated or at least semi-automated :)
Thanks
I asked this one yesterday and got some nice responses:
Stored procedures/DB schema in source control
The articles from K Scott Allen say it all:
http://odetocode.com/Blogs/scott/archive/2008/01/31/11710.aspx
Write migration scripts for all db changes and keep them in a repository. Enforce a policy of making all changes to the db only by running a script; that way there is a record of what has been done, and a way to revert it. Investigate whether there's a migrations framework available for your favorite language/db combination.
I use Visual Studio 2008 Pro create Database projects (Other project types -> Database). We already use SVN as a code repository, so a project with a bunch of .sql files representing your stored procedures is just another thing to put in the repository - you can see diffs/history etc. This works the same with VSS or any other repository you use.
The nice thing about Database projects is that your project will remember your connection string, and all you have to do is right click on a .sql file (or select all of them at once!) and select run to update it in the db. This makes it easy to update your .sql files from the repository and run them all to update all your stored procedures, verifying your database is updated in seconds.
You can also select create a LINQ project (Visual C# -> Database) and store all your LINQ code in your repository.
Hope that helps!
If you were super lazy you could use the SMO (SQL Server Management Objects) or if using SQL Server prior to 2005 the DMO (distributed managmeent objects) to script out all tables/views/stored procedures daily and then compare the script to the script in source control and if there are any changes check the new version in. You won't be able to necessarily have as pretty of a script as if you just created all db changes in scripts, but at least you can recreate all tables/stored procedures/views. For example, in my table creation scripts there are often comments.
Here is an article to get you started on scripting: http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated.
Again, this is mainly if you are too lazy to bother with version control and it won't help if you change something twice in one day. Also any data migration scripts still have to be saved and checked in because this won't pick up ad hoc SQL, only database objects.
I have written a DDL trigger which logs all the changes done to the definition of SQL objects (triggers, tables, SP, view etc). I could very well invoke extended SP from the trigger and store the details in another Database and use that as repository.
But if your team is really disciplined any source control should do the trick. The trigger is used as an audit mechanism and it's ideal for teams which are geographically scattered.
Try Randolph, One of the best SQL Version control tools I know.
I'm using Visual Studio Database edition which can export the schema from SQL Server in to a Visual Studio project. This is then stored in Source Control and can be deployed where ever needed. The VS Database project is just a bunch of scripts though and it's a clunky way of working.
A more robust method would be to use a database migration framework and if you're working with .Net check out this blog post for a good description http://flux88.com/NETDatabaseMigrationToolRoundup.aspx.
Update
As mentioned in the comments, this page is no more. So here is the last known snapshot from wayback machine http://web.archive.org/web/20080828232742/http://flux88.com/NETDatabaseMigrationToolRoundup.aspx