Visual Studio 2010 C# - application with centralized database - development - sql

I've started working on my database desktop application. The goal is to have one centralized database, so that each employee could connect.
My goals:
Centralized database on SQL Server 2008 Express
Use Sql to Linq
First run of application should create structure of database on server.
Now my question: how to do the last point?
I know that I can generate sql script via SQL Managment Studio and then execute it, but maybe there is some better way?

Like the comments said, I'm not sure why you would want to do this, but if you have one centralized database machine and you want to create a new database per user upon the first connection, then you could create one canonical/template database and the clone it via scripting on the first connect.
Your UI would say something like "Please wait while we create your new database..." and you'd run CREATE scripts for the database/tables/stored procedures/views/etc.
Just remember it might be a major pain to update the schemas of these databases once the cat is out of the bag.

Related

Avoiding data loss with a SQL Server script

I work for a customer who has his own database management team and I need to deploy my new web application version within a SQL Server 2008 script (I am not in position to execute any actions on their systems). I can't back up myself their database and I'm not sure they'll do it so if I delete all data it's gonna be terrible.
Therefore, I'm looking for a solution to back-up if possible the database, extract the existing datas, execute the new statements of my script, and re-include the datas saved in the database.
It is possible to do this in a SQL server script ?
More generally, how can I safely update schemas and datas of a SQL Server database within a script without losing all data inside ?
PS :
Currently, I'm using in the dev environment the initial database schema and the newest. So, I use Visual Studio 2012 with Data Tools to make Schema comparison and generate the update script.
You start with a copy of the database schema with sample data against which you can develop and test.
Then you write scripts (perhaps with the aid of a tool like SSDT) that updates the schema to be compatible with the new version of your application, retaining the data in the database.
You deliver these tested schema modification scripts along with the new version of your application for the customer's administrators to test and apply to the target database as part of the application upgrade.

Appropriate action installing another SQL application at work

hope everyone are okay...
I need to install any Sofware for the use of SQL. I'm just a begginer and started an online course. We have a account at work called Administrator and the only account has acces to SQL Managment studio 2014. Inside there are multiple databases linked to the external objects for stock contol purposes to collect data and view data, database was created by another company not us. Id like to download an SQL Software to run simple queries. But would need to know if it would affect any other databases or servers inside our network?.. just need to set it up for my local use.
Thanks

ASP.NET MVC 4 Code First Solution Setup Using SQL Server 2012

I am planning to create a web application using ASP.NET MVC4 using the code first approach.
I am using Visual Studio 2012 and I have SQL Server 2012. What I would like to do is setup the solution in a way that I can use SQL Server instead of the default being SQL Express or localDB. I would like to have the solution regenerate the database if any changes are made to the models and seed the database with some test data when that occurs.
I have gone through a bunch of tutorials and they all seem to be using the SQL Express or LocalDB database. I was able to get the solution to generate the database on SQL Server the first time it was run, but after I make changes to the model such as alter the schema name from 'dbo' to lets say 'test' or change the table name, it doesn't seem to pick up those changes.
Can anyone give me some insight on how I might be able to accomplish this?
Thanks
All you need to do is have your connection string in the web.config pointing to your SQL server for it to use that server instance.
As for having it update on model change, have a look into DropCreateDatabaseIfModelChanges.
In your Global.asax you can set your database initializer like this
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DbContext>());
You will need a using statement too
using System.Data.Entity;
There is a free video guide to MVC4 by Scott Allen which can give you more info on Migrations and Code First (which is what you are asking about). The 4th section of the video guide has a 13 minute segment on Data Migrations which is a full walk through. If you can spare the time, watch that for a full detailed guide.http://www.asp.net/mvc/videos/pluralsight-building-applications-with-aspnet-mvc-4
I might point out this is only useful in development and there is no way to make it work for production as you would lose your data. If you need something that is suitable for a production environment look into SSDT (SQL Server Data Tools). You can manage your database as a SQL project in your solution and deploy updates using a DACPAC file. The file manages all the updates in production and can be set to protect against data loss. You can change and deploy your Db from your project and still use EF with database first and EF models etc. All you do is make your changes in the Db project and hit debug to update your test Db. When publishing you can choose to export the DACPAC for updating live.

Automatic incremental SQL Script generation for incremental, nightly builds when using Team Build in TFS 2008 and Visual Studio 2008?

hope that everybody here is OK.
We are using VS 2008 as development tool, TFS 2008 as version control as well as build automation. Some of our developer use dbpro for databases changes and some use SQL Server management studio.
I am trying to automate build for Web Application built using C# and VB.Net.
Our scenario is such that we have a central database to which our web application connects.
Whenever we supply our clients with a new functionality or a bug fix, we supply them incremental builds.
The SQL script is checked into source control for every incremental build when they have made and tested there changes on our central DB Server.
I want to generate Differential script that can be run at the client as an incremental update script. Now to come about it is a problem. Sometimes our developers tend to forget the database change-sets and the script in the source control is missing an SP or a two.
Also, sometimes we need to insert default data into some of the tables that have strict stringent values and not test values. Like a table that contains Services provided by the panel, we add a new service name, signature, credentials and service address, etc etc in the ServiceTable. Besides this many other tables may have test data that may not be needed.
If we use DataCompare, it will generate changeset for required data (important for client to enable certain services) and our test data that was added to the database as a result of our testing of the functionality or bug fix.
Currently i am using SQLSchemaCompareTask (from Visual Studio 2008 Team Database Professional Power Tools API) in the TFSBuild.proj file of the build definition for TFS 2008.
Using SQLSchemaCompareTask, the script generated contains database names like [dbo]. etc which are not desired as the script fails when run against SQL Server 2000 databses (Some of our client still use SQL Server 2000) databases as teh backend of the application.
Also default data can't be generated by this process.
To overcome this problem, i have to come up with a solution that can compare databases and generate script automatically that does not have to be manually reviewed again before being sent to the client.
Please suggest effective methodology of such SQL script generation and suggest whether two different databases may be used or something ? Is there any toolkit or api that can enable build automation for SQL Server databases?
Thank you all.
Regards
Steve
Try to use SQL Examiner Suite for this:
http://www.sqlaccessories.com/SQL_Examiner_Suite/
The tool compares both schema and data and produces synchronization scrips (or differentials scripts). You can automate script creation with supplied command-line tool.
Rather than collating many individual change set scripts (and therefore occasionally missing objects out), why not use schema compare and data compare to create a single script from your database project using a database equivalent to your client's on the target? This should create a script tailored to their requirements.
In data compare you can exclude test data records that you don't want pushed to your client by unchecking them in the lower grid.

What is the best way to transfer a table or tables from one SQL server to another?

I have been developing in VB.NET and SQL Server 2008 for a while now, but haven't got into live installs yet. In the database system I used be on it had the ability to archive multiple tables into a .dga file, as it was called. I could then restore the .dga file into another database or on another server.
I'm looking for the easiest way to accomplish something similar in SQL Server.
If you want to transfer specific tables, then using Data Transformation Services (right click on the database in SQL Server Management studio and select "Import Data" and it will bring the dialog up for it). Of course, this assumes that you have both databases available to you.
If you are comfortable with replacing the database as a whole, you can easily backup the database and then restore it into a new one through SQL Server Management studio (or through calling the appropriate SP).
I would go for one of the following :
From MS SQL Management Studio, right click on the database / Tasks / Generate scripts
From Visual Studio, in the Server Explorer tab, "publish to provider"
Both will launch a wizard allowing you to export the tables you want the way you want (including data or not, creation scripts or not, etc etc.)
If you want to move tabless without data, the simpliest thing is to script the tables you want and run the script.
We script all our db changes and commit them to subversion and then run them as part of the deplyment process.
If you want to put the whole database on prod including data (scrub out test records first!), then do a backup and restore onthe other server.
For future changes, wescript all our db changes and commit them to subversion and then run them as part of the deployment process. There also are tools that look at the structural differnces bewteen the two servers and creates scripts. REd-Gate's SQL Compare is really good for this.
In addition to HLGEM's suggestions, you can look into SSIS if this is an ongoing process.