Configure VS2008 to create SQL Server databases instead of SQL Server Express? - sql-server

Probably asked and answered before, but difficult to search for.
In VS2008 when you right-click App_Data folder and create new database, it attempts to create a SQL Server Express database. Well I have SQL Server 2005 Standard installed and have thus uninstalled Express. How do I get VS2008 configured to know I want SQL Server databases (NOT Express) created?

SQL Server Express databases are SQL Server databases and vice-versa. While is true that the SQL Server 2008 database files format is different from SQL Server 2005 one, whthin the same version (2005, 2005 SP1, 2005 SP2, 2008 , 2008 SP1 etc etc) all SKUs (Express, Standard, Exnterprise etc) have all the same datbase format.
Yout Visual Studio tools are guiding you down the wrong path. You should not use the Solution Explorer to add a database to the App_Data folder. Instead you should use the Server Explorer tool (menu View/Server xplorer or press Ctrl+W,L) and connect to your SQL Server 2005 instance. Then use the Server Explorer tool to explore the database. To connect to the database from your solution, add a connection string to the web.config file.
While you can manage the database objects from the Server Explorer, thar is a horrible way to do it and will cause only pain on the long run. You should instead create deployment scripts with DDL statements and run those scripts when the solution is deployed. This way your database metadata is part of your source control and you can keep track of application database versions, see Version Control and your Database.

Related

Cannot restore a database with a .bak file due to another SQL server version

I have installed SQL server 2008 R2 and i try to restore a database a colleague sent me in a .bak file.
Unfortunately, i cannot restore the database since the database was saved on a server from version 10.50.1600 and my SQL server version seems to be 10.00.1600.
I tried to upgrade my SQL server with SP1 and SP2 packs but it didn't change anything.
Otherwise, i noticed by clicking on the server property that the line "product" displays Microsoft SQL server Express edition even though i have installed SQL server 2008 R2. That's at least what is displayed when i fire it...
Can anyone help me ?
Thanks in advance
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version (SQL Server 2008 R2 - 10.50.1600) of SQL Server down to an older version (2008 - v10.00.1600) - the internal file structures are just too different to support backwards compatibility.
You can either get around this problem by
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
Understand, what the version numbers mean. You need to be on R2 which is not just a patch or service-pack.

Database created in XP to be opened on Vista

I have a database in SQL server which is created on xp and to be opened on vista
When i try opening it on Vista.
Would this be possible
Thanks
Sun
SQL Server creates files that SQL Server can read. The file formats are independent of Windows versions.
What you should be aware of/considering are SQL Server versions and editions.
For instance, if you create a DB using SQL Server 2008 R2, you will not be able to attach/restore such a database using SQL Server 2005 or 2008, no matter what OS you're working on.
Similarly, if you've applied a particular service pack to the installation where the .mdf originates, you need to be working at the same or later service pack on the system where you want to read the file.
Similarly, if you create a database that uses features that are only available in higher level editions of SQL Server - i.e. something only available in Enterprise/Developer edition - you may have issues using the same database on a Standard Edition installation.
You don't open a sql server database with "xp" or "vista". You open the database in Sql Server. That's all that matters here: does the machine have the correct version of Sql Server available? Note that no version of Windows ships with Sql Server installed by default.
Also, unless you're talking about Sql Server Compact Edition you might want to re-think this. Full editions of Sql Server belong on the server editions of Windows. If you're building a database for an app that will live on individual user's desktop and the database will only serve the instance of the app on the machine, do not use sql server for that database. Instead, use something like Sql Server Compact Edition (it uses a different engine than full sql server that is more desktop-friendly), SQLite, or even Access.
Yes, there is no reason why this should not work.
As #Demian said, you can not open database created in SQL Server 2008 R2 in SQL Server 2008. But alternatively if you are sure that your database is not using any features specific to R2, you can script out whole database and then create similar database by running those scripts into SQL Server 2008 (ofcourse with some changes in script). And then just write some insert scripts to import data from 2008R2 to 2008 (Or you can use SSIS to dump data from one location to another location)
I think the question itself is pretty unclear. No explaination of environment of both XP and Vista machines (e.g. DBMS versions including SPs) or how you are trying to open/access database (using attach or by restoring backup). Without proper information I don't think there is any EXACT solution.

Problem with importing an mdf created with SQL Server Express 2008 into SQL Server 2005

The question is probably extremely easy to resolve, but I need to resolve it because I need to carry on with my project. I am using SQL Server Express 2008 at home, and I've been working on an ASP.NET MVC app that stores my DB in an mdf file in the project's folder. The problem is that the SQL Server in the Uni labs is SQL Server 2005, and when I try to open the mdf file with the VS Server Explorer,It says that the version of the mdf file is more than the server can accept.
The only option that comes to my mind is exporting the DB as an sql file, just like I've done it thousand times with phpmyadmin. the thing is that the SQL Management Studio Express is not the most usable tool in the world, and for some strange reason all the articles I could find in Google were irrelevant. Please, help.
It is not possible to attach database created on SQL Server 2008 to SQL Server 2005. The other direction is possible.
Your only option is to script the database and data and run the scripts on SQL 2005. If you have used any of new features of the SQL Server 2008, you will have to rewrite the scripts.
I haven't used it much, but right click on database -> Tasks... -> Generate Scripts... / Export Data... / Import Data... should do the job right.
Google "Database Publishing Wizard", it's a tool from Microsoft to script an entire database, both schema and data.
you can script your db and its data. then run it on the target server to create a new db that is compatible with 2005 version.
Tools like Red-Gate SQL Compare and SQL Data Compare can compare a live database to e.g. a backup file, so you could compare your SQL Server 2005 database against the SQL Server 2008 Express backup file, and move data that way.
Or you could possibly generate INSERT statements for your tables that have changed data using a tool like this one here or this one here. These can generate INSERT scripts for your tables, which you can take along and run on your SQL Server 2005 target system.

Visual studio 2010 and Sql Server

Do visual studio 2010 include already Sql Server instance, or I need to install Sql Server developer edition to develop an application that need a Sql Server db.
If it installs a Sql Server express edition, it this enough or it's better to have Sql Server developer edition?
I would second that installing the "full" SQL Server Development Edition makes sense if you do serious database development.
However you can have both installed side by side, and having SQL Server Express is very useful for one reason - it supports placing database files in the App_Data folder of ASP.NET applications. While I don't do this for my own projects, it's a very nice feature for demos or open source applications you download from the web: just unzip, start VS, hit F5, and you have a running solution including database. Without SQL Express, you first have to move the MDF file, attach the database, set up user rights, replace the connection strings etc...
The Visual Studio 2010 installer gives you the option of installing SQL Server 2008 Express Edition. This edition of SQL Server is good enough for development purposes but is not intended for production use.
I think the size limitation is not the main issue.
In Sql Server 2008 you have some features in Sql Server Management Studio that aren't available in the Express management Studio or the Express database engine, like:
- suggesting the table and column names (in Query Window)
- Sql profiler
Cor Westra

Importing a MDF file into SQL Server 2008?

I have inherited a VB.net web app that I'm making some changes on. I'm perfectly capable with the programming side (VB and MSSQL) but I'm getting lost with the tools. I was given a zip file of the code and everything. I opened the sln file in Visual Studio 2005 and it worked fairly easily with little modification.
Running the app works perfectly. Problem is, I need to write some new SPs so need the database admin. SQL Server 2008 Express is installed but it doesn't see any database and I have no idea how to import it.
I have a folder App_Data in the project with the file ASPNETDB.MDF. Opening this in VS gived the error:
This server version is not supported. You must have Microsoft SQL Server 2005 Beta 2 or later.
Any ideas where to go from here?
You need to get Sql Server Management Studio. From there you should be able to connect to the instance of Sql Server Express running on your system and tell it to attach to the .mdf file. This will allow you to use that database from withing sql server and management studio, and you will be able to add your stored procedure. Just remember to detach again when you're done, or you won't be able to use the mdf file as you expect from your app.
Visual Studio uses SMO 2005 to connec to to SQL. The SMO 2005 will not connect to SQL 2008 by design. You need to either upgrade VS to VS 2008, or downgrade Express to Express 2005.
You can't attach mdf file made in SQL Server 2005 to a SQL Server 2008 instance. What you need is to install SQL Server 2005 Express, attach this file, backup database, then restore it on 2008 Server instance and detach the database. You will get properly created for 2008 Server mdf.

Resources