I am working on visual studio 2010 and i have a database in Server Explorer that i can see that is not in the App_data in the solution explorer.. I need to copy it somewhere to upload it to the host..
I think the database is suitable for SQL server2005 , cause that is the only sql server version installed on my computer with the vs2010.
Here are my connection string:
<add name="YourGuruDB" connectionString="Data Source=DIMA-00AA1DA557;Initial Catalog=model;Integrated Security=True" />
You can back up the database by right click on db and choose back up. Restore it on your host /web server.
I would prefer to export you database schema and mandatory data as sql scripts using SSMS (SQL Server Management Studio) then run the script on the host.
Here is a great tutorial about it http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/
EDIT: if you are using VS2010 there is a new feature in the deployment called "Package/Publish SQL" allow you to package your SQL DB. Here is a tutorial how to use it http://rachelappel.com/deployment/database-deployment-with-the-vs-2010-package-publish-database-tool/
Erm. your connection string says the database in use is model. That's a special database in SQL Server that's used a template for new databases (that's why you can't detach/copy). You're going to have all sorts of problems if you stick with that name.
But DO NOT rename it. You're going to have to create a new database - which will have everything you've put in model in it. Then remove everything you've added to model.
You should now be able to detach your new database and move it elsewhere.
Select you database in SQL Managment Studio.Then Tasks\Detach.
After this you can copy the database files to another distination. To make you database on-line again, just do Tasks\Attach.
P.S It's only the one among other approaches to accomplish your task.
Related
I am following this tutorial (http://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database) in order to create a database-first app with Entity Framework.
I hit "Run" and everything seems to be working, but in the next part of the tutorial (https://www.asp.net/mvc/overview/getting-started/database-first-development/creating-the-web-application), when I try to add a connection, it's not in the drop-down menu in the "Connection Properties" box under "Select or enter a database name".
Which server is the database on? I didn't specify anything about the server when I created the project for the first tutorial, and I figured that it would be on the default LocalDB that comes with Visual Studio (server name: (localdb)\MSSQLLocalDB), but the database isn't there. Any ideas where I should look or what to try?
Maybe use . (a dot) as Server Name?
Open your Web.config file and check your <connectionStrings> this is where the data source of the database will be. As shown:
However, which version of SQL Server do you have? As this can determine what the correct connection string will be.
Hit Windows+R. And run the following:
%LOCALAPPDATA%\Microsoft\Microsoft SQL Server Local DB\Instances
You may have multiple instances, it would be worth checking each one. So it would be:
(localdb)(name of instance)
This article may also be of use to you:
http://rajchel.pl/2015/10/solving-connection-issue-with-sql-server-2014-localdb/
What could be the case is that you have to run the application you created, and then do something to touch the database like creating / registering a user. After registration you can find the database on the specified location in your web.config settings. This was the solution in my case.
I have been using a central MS SQL database located in the cloud to develop a web site project. I have recently found myself in situations, when I need to develop without the internet connection. I want to begin to use a locally available copy of the existing database, put it in App_Data folder.
What is the correct set of steps I need to undertake to get the project to work with local DB?
For example:
Detach a db from an existing SQL instance.
Copy to a development machine.
etc.
Moving a SQL-Server DB is not that hard. Look here for some methods to do it.
http://support.microsoft.com/kb/314546
I usually find the sp_detach + sp_attach method really easy.
I would create an empty shell database locally, then use one of the many schema comparison solutions available to make the local database look exactly like the cloud database.
Correct way is to create and regularly update your standalone copy of database using import/export. In particular MS SQL Server provides Import/Export Wizard tool for such purpose.
Make a backup
Copy backup file
Restore on your server
Restore/organise users
I am taking over the maintenance of a website. Virtually no documentation. I hope that this kind of question is "ok" here ...
Right now, I am trying to locate/view the database but I can't find it.
This is the only connectionString in web.config:
<connectionStrings>
<add connectionString="Data Source=YPOC\SQLEXPRESS;Database=Marco;User ID=yyy;Password=xxx;" name="DefaultConnectionString" />
</connectionStrings>
QUESTIONS:
1) are these parameters equivalent?
a) Database=Marco
b) AttachDbFilename=|DataDirectory|\Marco.mdf
c) Initial Catalog=Marco
2) if the answer to #1 is "yes", then I should find a database file called Marco.mdf in the App_Data folder, right?
3) but #2 can't be correct, because I do not see a database file called Marco in the App_Data folder ... ;-x
4) where in the world is carmen sandi ... oops, I mean Marco.mdf ?!
RELATED QUESTIONS:
I had to copy all the files from a production server called YPOC. In the web.config, I think I need to change "Data Source=YPOC\SQLEXPRESS" ... my SQL Server Instance Name is "SQLEXPRESS" ... therefore, should I change the DS to "Data Source=.\SQLEXPRESS"?
In the App_Data folder, I found ASPNETDB.MDF ... in Server Explorer, I try to connect to view the tables, but I get an error message:
"...cannot open because it is version 661. This server supports version 655 and earlier"
I did some research and it appears that version 661 means that it needs SQL Server 2008 R2 ... but I have that installed already ... ;-(
I'm used to a shared hosting environment where the SQL Server DB is set up and it's easy to connect. Here, it is on a dedicated cloud server (unmanaged) and I'm been thrust upon new territory where I can't even find the database ... ;-(
Any help is greatly appreciated ...
nano
Stop, stop, stop, stop, stop using the User Instance and AttachDbFileName nonsense. Please. You will be much more sane if you forget they exist. I'm totally serious. The user instances feature has been deprecated for a reason.
Take your MDF file, which you can find by searching using Windows Explorer (if you've been using this user instance feature, you will probably find multiple, and I have no suggestions for determining which one is the right one). Once you've found the one you want to use, attach it to a proper instance of SQL Server using CREATE DATABASE Marco ... FOR ATTACH_REBUILD_LOG. Your connection string should then point to your server (yes, .\SQLEXPRESS should be fine if you are connecting locally), and should refer to your database by logical name (e.g. Marco, no path information to a specific MDF file).
Also you'll want to install Service Pack 1 for SQL Server 2008 R2. It seems like you created a database in a post-RTM build of SQL Server 2008 R2 (or in 2008 with SP2+).
"But how do I access this database from my dev computer when I don't know the SQL server address, etc?"
I found the Marco database. It is on SQL Server that is located on an unmanaged web server account. The way to access the database is to use a Remote Desktop Connection, then use SQL Server Management Studio that is located on the server (not my dev desktop). The SSMS then found the server/database and voila, connected ... my confusion was in trying to connect using SSMS from my dev desktop directly instead of using SSMS located on the server via RDC ...
I've created an entity model file (.edmx) based on an .mdf file in my asp.net application, placed in my App_Data Folder.
first of all my connection string, created by the entity framework wizard :
<connectionStrings>
<add name="Sales_DBEntities"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;attachdbfilename="c:\users\ext\documents\visual studio 2010\Projects\WebProject_A\WebProject_A\App_Data\Sales_DB.mdf";integrated security=True;USER INSTANCE=TRUE;multipleactiveresultsets=True;App=EntityFramework'"
providerName="System.Data.EntityClient" />
</connectionStrings>
The above is placed in an app.config file created by the wizard.
I've copied the same connection string to the web.config file as well (I'm not sure if this is necessary).
I've come across two problems when attempting to later run the same application on a my machine (I've created the application on a different machine).
The first was regarding the user instance:
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed
The first thing I don't really comprehend is what a user instance actually defines.
According to MSDN :
A user instance is a separate instance of the SQL Server Express Database Engine that is generated by a parent instance
Is my local database considered a user instance ?
I would really like some clarification on the matter because I came across posts suggesting
to mark it as False, and the reason was not clear to me .
another post on this matter
From there I came across another solution that explains that for this problem you need to
enable user instance in the SQL Server on your machine.
The Fix
I've done what was explained in that post
but now I've come across a new problem :
An attempt to attach an auto-named database for file (Full Path to my app_data\my.mdf file) A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
I've already attempted to delete all the files under
C:\Documents and Settings\(your user account name)\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS
and rebooting like suggested in other posts, but still I can't find a clear solution for this problem.
I know this is a long post but any help would be appreciated
thanks in advance.
Read this very good overview of what user instances really are.
In a nutshell:
SQL Server allows you to have multiple instances of itself on a single computer - the default instance can be accessed using just the machine name (or IP address) of the host machine - all other instances need to be specified by an instance name (like the SQLExpress on your machine)
for development purposes, you can also create a user instance - each user gets their own separate instance of SQL Server (works in the Express edition only) and a database is attached by its file name (path\Sales_DB.mdf) to that user instance. This instance is started up on demand, then runs and is shut down when no longer needed
While this works great for development, it's not really intended for later on - certainly not for production use.
In a production environment, you want to attach your database files to the actual SQL Server instance they should run on - typically using SQL Server Management Studio. When you do this, you no longer refer to that database via its file name, but instead you use the database name that was given to the database when being attached to the server. In this case, SQL Server will handle all details of operations - and that SQL Server instance is up and running all the time (doesn't need to be started "on demand" all the time), and you can use things like permissions and logins to control access to the database.
Your connection string would then look something like this:
<connectionStrings>
<add name="Sales_DBEntities"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='server=YourServerNameHere;database=Sales_DB;integrated security=True;App=EntityFramework'"
providerName="System.Data.EntityClient" />
</connectionStrings>
When you have attached a database to a production (or testing) SQL Server instance, you do not need to know what the files are that make up the database, and you don't need to specify those files - SQL Server will take care of that. You just refer to the database via its database name.
The solution is always simpler then anticipated:
double click the model.edmx file -> the designer will open.
right click on the designer -> Update model from database .
new connection -> Choose Database file (.mdf) under type .
Browse -> go to your App_Data folder, and choose the DB.
copy the connection string created in App.config to web.config.
bye.
I am building a blog-like publishing system on ASP.NET 4.0 (with EF 4.0) that I want to be very easily deployable/backupable in the first place. I am at a decision point of whether making the system to create a database in an SQL Server and use that (traditionally), or have a App_Data MDF file in the site and just attach to that one with SQL Express. I know the memory/size limitations of Express editions, and I won't be hitting the limits as this is not a performance-critical business application or any serious stuff. Just a simple CMS with blogs/writings/photos (actual photos are NOT saved in database, just their paths are saved in MDF) and that's it. I see no problem using MDF, but I'm not an expert on the topic too as I've never worked/created a website using MDF file. I always deployed on the SQL Server, but I don't want to deal with users/roles/permissions and the last thing that I want to have a user having installation problems due to database settings.
What should I go with? Any problems that I would face with MDF? Recommendations?
IF you use SQL Server Express - which is a server - I would always opt for a "real" database approach: attach your database to the server, access it by its database name, deploy SQL scripts to update it.
That "attach DB from file path" always seemed like a half-baked and rather messy kludge to me.....
If you don't need that kind of power - investigate SQL Server Compact Edition which is a one-file only, in-process database. It has its limitations - no stored procedures, doesn't support certain data types like VARCHAR(MAX) or XML - but for easier scenarios, it's perfect and easy to use - just deploy it along your app. It's single-user, e.g. you don't share the data between several clients, it's a local store for each user/app on its own