Change database schema in published Lightswitch application - vb.net

I have created a functioning LightSwitch (Visual studio 2012 Pro) application...
Now it's time to publish! The only problem is that I can't seem to figure out how to change the schema name to something other than dbo.
That is, I don't want the output tables to be dbo.XXXX, I want them to be my_schema.XXXX instead.
Also, note that the database is on SQL Server 2005.
Does anyone have suggestions on how to achieve this?
Thanks!
Update: Sorry for not being specific. I don't want to change the schema for existing tables in my database. I want my LightSwitch application to use the new schema. I don't mind publishing it and then modifying the schema on the tables, if I can then somehow also modify the LightSwitch application to use the new schema. But ideally, there would be a way to tell LightSwitch to use a different schema when it publishes.
For those who don't know what LightSwitch is, it is a Microsoft .Net Rapid Application Development tool for SilverLight business applications, and is built into Visual Studio 2012. My application is written in VB.Net

You can't change the schema name for an intrinsic database (the database that is created with LightSwitch). Maybe you'll be able to in V3, but you can't currently do it in V1 or V2. To achieve this, you'll have to create the database in something like SSMS (SQL Server Management Studio, then attach to it as an external data source.
Seeing as you've already done all the creating in LightSwitch, you could publish it as is, then attach to it as I mentioned above. I hope you don't have screens created, because unless you want to manually edit all of the lsml, you won't be able to use the attached database in any already created screens.
Any time you need to do something "out of the ordinary" with LightSwitch's database, you need to create it outside of LightSwitch, then attach to it. Why? LightSwitch was originally created with the idea in mind that the users didn't need to know anything about SQL Server.

Related

SQL Database in VB.NET Application

I'm fairly newb when it comes to programming and even newer when it comes to database management and integration.
So I have a VB.NET Windows Application that uses a SQL Database. I use LINQ to SQL to fill datagridviews in windows that show table data and also use LINQ to SQL to save data to the database.
All works wonderfully however...
When I publish the application, the database isn't external as far as I can tell. It seems to build itself into the application so once the application is installed, the database is there, it views and saves data, but if the computer crashes or the application is uninstalled, all that data is going to be lost without a way to back it up.
I'm using Visual Studio 2010 Express. I created the SQL Database in VS2010-Exp as well. I feel like there's something simple I'm missing here. When the application gets published and then installed, where is the physical database going?
Thanks!
It is running as part of the application. If you wanted a separate, central database, you would need to have an instance of SQL server running in some accessible location.

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.

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

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.

Visual Studio Database Project and SQL Server Management

I enjoy using SQL Server Management Studio for change and updating my database. Its easier, faster, and safer than writing changes myself.
I was looking into using some sort of version control for databases and read about using a SQL Server Database Project in Visual Studio 2010.
I scripted out an existing database and imported it into a new SQL Server Database Project. Now, from what I can tell, there is no GUI to edit the database; I can't add columns, change datatypes, or edit existing data without scripting it myself. For instance, in SQL Server Management Studio I can right click on a table-name and select "Design" and then add/edit columns, change datatypes, etc from there.
While Visual Studio's Database Projects has some features SQL Management Studio does not have I don't think I can live without a "table designer".
Is there a table designer built into VS's Database Project I'm just not seeing?
No, there's no table designer.
If you're starting to think about version controlling your database, you ought also to be thinking about writing actual SQL to implement your database objects. That's the route that the Database Projects force you down. If you can't write the SQL for your database changes, how are you going to be able to review and appreciate a diff between how a table was 6 months ago, and how it currently is in your project?
I've been using VS2008 Database Projects for about 10 months now for our version control. Every now and then I do still use the table designer, it is a quick and easy tool. I believe the majority of your question centers around workflow as this is what I found to be the most challenging part about development in a version controlled environment. I would recommend continuing to design your objects in Management Studio or however you're comfortable and then do a create script and import that script into your Database project. There are some quirks when doing this, you'll need to always script the create statement even if you're performing an alter in your environment. As well you'll need to remove any USE statements for your database as the context in which you're importing your scripts will always be in the project you're importing to.
We have found that a successful workflow for us to facilitate code deployment is to have a production branch which is branched to a Main (development branch) and then to test. All new development is done in Main and merged by changeset to each other environment as required.
You can import your scripts from your development environment by right clicking in the solution and clicking import scripts. I recommend that you check all the options to overwrite objects that exist, import extended properties and import permissions.
After changing your DB schema using SSMS's GUI tool, you can use Database project's Schema Compare tool to update your project files (set the source to be your database and target to be your project). This way you can keep using GUI tool to manage the schema and the database project will manage the versioning.
There is no visual table designer in Visual Studio 2010 Database Project. But, concerning version control for databases, there is a workaround - you can use SQL Server Management Studio together with Red Gate's SQL Source Control. It costs some money but definitely is worth it.

References/walkthroughs for maintaining database schemas with Visual Studio 2010?

I have Visual Studio 2010 Beta 2 and SQL Server 2008 installed. I'm working with a populated database and want to modify various column types. SQL Server Management Studio requires me to drop tables to do this, and get pretty finicky given my moderate level of knowledge of SQL Server.
However, I heard the new database project type supports changing the database schema to the desired format and it will handle creating and running all the scripts to implement the changes.
I've created a VS2010 database project using the existing database as the source, but so far haven't had much luck figuring out the appropriate method to make the changes without getting an error.
As a result, I'm looking for any reference info I can find on using VS2010's capabilities in this area. Any suggestions?
write scripts instead of using the gui. You can use alter table for instance to change a column. Never use a GUI of any kind to create a change to a database table.
Here's a walk through of the new VS2010 "Deploy-SQL" tab in the properties page of web application projects.