How to delete Sql Server Database - visual-studio

I created a database using Server Explorer Visual Studio of name MyDatabase.mdf (and MyDatabase.ldf). Now i want to delete it.I deleted it from Visual Studio using Server Explorer (means removed reference). Then i deleted MyDatabase.mdf and MyDatabase.ldf files from my C directory (C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL).
But when i try creating a new database with same name (MyDatabase), it gives an error and says, database name already exists, try some other name.

There are probably metabase attributes still left in your master table referencing your deleted tables. Instead of just deleting the MDF and LDF files, I would recommend using T-SQL DROP DATABASE statements. If you have MS SQL Management Studio, you could also right-click on your database and choose the "Delete" option.

Are you creating a User Instance of the database? If so, remove the "Initial Catalog" parameter from the connection string in the solution in Visual Studio if you have it defined.

Related

How do i change SQL database NAME in visual studio 2012

I changed the name to fish the old database comes back, when I look in App_data folder in file explorer I find the old database named food. So the website is using the old database. Also I've change the name in web.config.

How do I import the subset of a database into a visual studio 2013 project

I'm trying to upgrade a Visual Studio 2008 database project to a visual studio 2013 database project.
I've been getting an error like
[dbo].[trigger_name] has an unresolved reference to object [dbo].[table_name]
From what I've read here, it seems to say that you can import a subset of a database somehow:
SQL Server Database projects are meant to mirror fully the databases
to which their contents will be deployed. Although you can create
projects that contain just a subset of a database—for example, the
assets for a SQL CLR assembly—SSDT will block you as soon as any T-SQL
in the project references an object in the database that is not also
in your project.
Since I only need 10 tables for my script to run, how do I create these tables in my project, so that I no longer encounter the aforementioned error?
Or, is there a way to link to a database on a server and allow my triggers to verify the object against the actual database schema?
You can create a new db project then right click on it and choose Import database. In
the Import wizard you will choose which table you want to be imported.
Once you have it imported then go to your actual database project and add database reference which will point to the newly created project.
Second method is to add those 10 tables to your existing project. Right click on the project name and choose Schema Compare. Set your project as a target and Sql Server database as a source, click Compare, choose your tables and click Update target.
You can't add a reference to sql server directly.

Database Schema Viewer functionality in vs2013

Recently migrated from vs 2010 -> vs 2013. Observed that there is no Database Schema Viewer in vs 2013 for DB projects. SQL Server Explorer does something similar but when you add new items (say a new table) to a project, noticed two things:
1. the new table file gets created in the root folder and not under the Schema Objects\Schemas\dbo\tables\
2. In vs2010, the table scripts used to have extension XX.table.sql but in vs2013, its always XX.sql
What actions can i take to achieve the above 2 behaviors as in vs 2010
Schema View is no longer part of Visual Studio. You'll have to use a 3rd party tool. If you have SQL Server Management Studio then you can use its database diagrams feature.
Visual Studio no longer manages the folder structure in database projects. When adding a new item, you should add it to the appropriate folder yourself.
To include the schema name in your files go to the database project's properties, select the Project Settings tab, and check Include schema name in file name. This change is not retroactive.

Visual Studio 2010 cannot add reference because it cannot connect to SQL server

I'm pretty new to Visual Studio so this might be an easy issue :)
I have created a Visual C# SQL CLR Database project where I have created a Trigger. This trigger is supposed to access an IIS on another machine in the network. In order to do this I found that I needed System.DirectoryServices but when I added this VS complained that I needed an assembly. Then I found that I should run the CREATE ASSEMBLY in the MS SQL SERVER. Did that successfully and successfully added my database as a data connection (Server Explorer -> Data Connections). In the Assemblies subfolder I can see the System.DirectoryServices but cannot reference it from the add reference... (when right-clicking references in the solution explorer). When trying to add a reference I have two tabs: Projects (empty) and SQL Server which gives the following error:
The connection to the database failed for the following reason: There
is no available SQL server connection.
No server references can be added at this time, but you may continue
to develop the project.
When I try to add a server connection to either localhost or the machine name of my computer it seems to do nothing (no error but also no server is added in the server explorer).
In Solution Explorer, right click on the Project and select 'Properties'. Select 'Database' tab on the right hand side, then browse to your database or insert a connection string.

Error opening the .mdf file to app_data

I am not able to add .mdf file in App_data(vs 2010 visual studio).
If I right click on App_data and try to add existing item and select mydatabase.mdf and click OK I am getting this error:
The file can not be opened because it is used by another process.Please close all applications that might access this file and try again.
But I am just running visual studio.
Not sure if you have found a solution for this, but I just ran into the same problem. I found some relevant info here:
How to add a new database under app_data with SQL Server Enterprise Edition
From this I gather that adding new AND existing databases (ie the .mdf file) via VS2010 is not possible.
I'm assuming (for this answer) that your end goal was the same as mine, i.e. to use the Microsoft Entity Framework to generate a model class from the database.
As I didn't want to install SQL express just to do this my solution was:
-Create any new db via SQL Server 2008 MGMT studio (or a script if you are that way inclined).
-Add a CONNECTION to the database in VS2010
-When adding a new model using the 'Entity Data Model Wizard' select 'Generate from database' and then select your existing connection, and the relevant table(s).
Worked for me!

Resources