Good day once more.
Okay so what I want to do is to keep my database in the App_Data folder for ease of use, now I thought this would be easy: Copy the database into the folder and change the connection string. But when I try that I get the horrible version error:
The database
'C:\USERS\GUÐMUNDUR\DESKTOP\TEST\TEST\APP_DATA\IRIS2.MDF'
cannot be opened because it is version
661. This server supports version 655 and earlier. A downgrade path is not
supported. Could not open new database
'C:\USERS\GUÐMUNDUR\DESKTOP\TEST\TEST\APP_DATA\IRIS2.MDF'.
CREATE DATABASE is aborted. An attempt
to attach an auto-named database for
file
C:\Users\Guðmundur\Desktop\Test\Test\App_Data\IRIS2.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
Now I was wondering if anyone can suggest a solution to this, I can recreate the database via the SQL script so there is no problem with that and there is no important (yet) information there.
Any ideas?
Here is the connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|IRIS2.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
The solution I used
I went into the SQL Server Management Studio and attached the database there while keeping it in the App_Data folder. Than I went into Visual Studio, created a new Data Connection and after it was created I clicked on it and went into Properties tab for it and selected everything from the Connection String and replaced what I originally had with it.
So the connection string looks like this now:
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=WODAN;Initial Catalog=IRIS;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Here are the instructions for the attachment process (as supplied by Ladislav Mrnka)
msdn.microsoft.com/en-us/library/ms190209.aspx
Thanks to everyone for their input and special thanks for Ladislav for helping me through out.
It means that your .mdf file was created by newer version of SQL Server. 661 should be SQL Server 2008 R2 and you are probably using only SQL Server 2008 (that is the version you can install as part of Visual Studio 2010 installation).
Version 655 is SQL 2008. 661 is 2008 R2. The box doesn't know how to handle the newer version.
In the Add Connection dialog, click on the Advanced.. button. Find the Data Source property and make sure the drop down matches the instance you're using.
Jumping in Late. Here is what I found.
One might have both 2008 and 2008 R2 Installed on their system. But if you see the error saying it cannot open 661 version, then update your SQL Server Express to 2008 R2. It will fix the issue.
MDF files can be opened directly in your visual studio as long as your are using express edition of SQL server.
Related
I am trying to attach database file in SQL Server. I am getting the below error. The same error I am getting while trying to attach database from Visual Studio. I am using Visual Studio 2013 and SQL Server 2014 Management Studio.
My connection string:
<add name="Sample"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\M\Desktop\SampleApplication1\App_Data\Sample.mdf;Initial Catalog=SampleDBContext;Integrated Security=True;"
providerName="System.Data.SqlClient"/>
Error:
The database 'sample' cannot be opened because it is version 851. This server supports version 782 and earlier. A downgrade path is not supported. Could not open new database 'Sample'. CREATE DATABASE is aborted.
and here is the default SQL Server instance is set in Visual Studio.
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility. Obviously, your database is from a SQL Server 2016 pre-release (internal version: 852) while the engine you're trying to attach it to is SQL Server 2014 (internal version: 782).
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.
I was having this issue while following an old Pluralsight MVC4 tutorial.
The course was asking me to use v11.0, but I was running a 2015 version. I opened up the SQL Server Object Explorer and looked at the different versions of LocalDB, and grabbed the name of the one that had my database in it (right-click "Rename").
I then pasted the name in the Add Connection window, under Server Name. Clicked Refresh, and voila, there it was. Hope this helps anyone out there.
This Microsoft link may resolve your problem if you are still running Visual Studio 2015 and seeing this error - the answer above is part of the answer. (megamaiku) The "generate scripts" answer from Mark_S will work assuming you have no trouble mounting/accessing the database. If I recall the SQL Compare is rather expensive but that is a great solution, again, assuming you can mount the database created by your Visual Studio application.
A similar issue arises with Visual Studio 2017 and SQL Server 2017 except you see 852/856 as the version problem.
After moving the database, change your web.config connectionString to match your server; (localdb)\MSSQLLocalDB or possibly localhost depending on what you are running
(SQL 2016/2017/2019).
<add name="DefaultConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;myDB.mdf;Initial Catalog=MyDBName;Integrated Security=True"
providerName="System.Data.SqlClient"/>
OR
<add name="DefaultConnection"
connectionString="Data Source=localhost;myDB.mdf;Initial Catalog=MyDBName;Integrated Security=True"
providerName="System.Data.SqlClient"/>
An old article explains how to pull the pieces from the database one at a time and if you're lucky and it still works (it did a decade ago - separate and then put the parts back together), you may be able to get what you need - a newer version restored to an older version. I am unable to find a reference to the trick but rather than scripting your entire database, there is a way to restore down by restoring the header (restore headeronly), then once the header is in place on your server and the permissions and so on are matching, you can restore that database from the newer backup.
However, the generate script is less convoluted and more popular.
I don't know how can I deploy my local Umbraco 7.2 local website to a normal server (Windows 2012 VPS). I know I need to copy all files to the server, but I can't figure out how can I copy the database. I download an SQL Management Studio 2012, but I don't know the access details, because when I installed the site to my localhost, the installer didn't ask me. Maybe on thing, as I remember, the DB type. It was SQL CE.
Does anybody know how can I access to the local and server database? Whats is Umbraco database name?
Is there any else configuration?
Maybe an easier option to deploy?
You can:
Open the database \App_Data\Umbraco.sdf see How do you open an SDF file (SQL Server Compact Edition)? (it is not in new SQL Management Studio versions) and do your database things to deploy.
Copy the SQL CE default \App_Data\Umbraco.sdf
Create a package
Using tools like Courier
And see the web.config for your connectionString:
<connectionStrings>
<remove name="umbracoDbDSN" />
<add name="umbracoDbDSN" connectionString="Data Source=|DataDirectory|\Umbraco.sdf;Flush Interval=1;" providerName="System.Data.SqlServerCe.4.0" />
<!-- Important: If you're upgrading Umbraco, do not clear the connection string / provider name during your web.config merge. -->
</connectionStrings>
I am getting the following error whenever I am trying to open the db_name.mdf file:
The database '{path}\db_name.MDF' cannot be opened because it is version 706. This server supports version 662 and earlier. A downgrade path is not supported. Could not open new database 'db_name.MDF'. CREATE DATABASE is aborted. An attempt to attach an auto-named database for file {$path}\db_name.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Connection string as follows:
<add name="PasswordDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\db_name.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
I am working on a asp.net mvc 4 project within visual studio.
Any help to get the issue resolved are very much appreciated. Thanks.
LocalDB is a new feature introduced in SQL 2012 Express - you will need to install SQL 2012 Express LocalDb if you need to use an MDF in this manner.
Krzysztof Kozielczyk has blogged several entries around on LocalDB here - take note especially of the issues when running under 'Full IIS'.
IMO using LocalDb with ASP.NET is for a developer machine config only - i.e. when you are ready to deploy your (code first?) MVC 4 app to a testing or production environment, you should consider attaching ASPNETDB.MDF more permanently to a SQL Instance.
You cannot attach a MVC 4 localDB in SQL Server 2012 Management Studio. You'll need to connect directly.
Open up SQL Server 2012 Management Studio. You can download a free express version here:
http://www.microsoft.com/en-us/download/details.aspx?id=29062
During installation make sure you check the localDB component to be installed.
After installation, open Management Studio and the "Connect to Server" dialog will appear.
Enter (LocalDb)\v11.0 in the Server Name textbox. Use windows authentication and click connect.
Your asp database will show in the manager. You can then script it out to what ever you want and edit the DB and make the appropriate changes to your connection strings in your web config.
Remember that if you're using Code First, which in VS 2013's MVC Internet template uses, you'll need to check your db creation code in your app start folder.
LocalDB was created so you can create data driven web applications without the overhead of a full version of SQL server running on your development machine. When you deploy to a production server, migrate to a full SQL Server instance.
Hope this helps :)
Set your database connection string to your Locally installed DB is as below.
Web.config :
<add name="ContextName" connectionString="Data Source=ServerName;Initial Catalog=DBCatalogName;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
I have a C# app written using Entity Framework 4.3.1.0 that talks to a SQL Server 2008 user instance on my development machine in Visual Studio 2010. It also works on my laptop in Visual Studio. But on the customers desktop PC, with SQL Server 2008 R2 I can't connect to the database with the application. The error is
The underlying provider failed on Open
All three computers are Windows 7 64-bit, but the app is 32 bit.
I suspected the connection string in myapp.exe.config, but it is the same as the one I use in Visual Studio.
In doing the research I have come up with two possibilities.
Does the same connection string work with SQL Server 2008 and SQL Server 2008 R2?
Does the location of the .mdf / .ldf files matter, I initially installed them in the application folder, but there may be a better place, like a predefinded AllUsersAppData. Is the application folder read-only for the server files?
Here is the ConnectionStrings section from app.config. I don't know if both are required.
<connectionStrings>
<add name="DataClass.Properties.Settings.SWDatabaseEntities" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SWDatabase.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="SWDatabaseEntities" connectionString="metadata=res://*/SWDatabaseModel.csdl|res://*/SWDatabaseModel.ssdl|res://*/SWDatabaseModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\SWDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
It started working for some reason after I removed an errant from mcahine.config that an IBM Client had installed. It didn't work right away, but I don't know what else changed. Maybe it was after a reboot.
I generated a database through entity framework. Here is the connection string:
<add name="AnnouncementsContainer" connectionString="metadata=res://*/Models.Announcements.csdl|res://*/Models.Announcements.ssdl|res://*/Models.Announcements.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Database.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This uses a file called Database.mdf. The application runs fine but there are two issues that I am having to deal with right now:
Database Updates: Whenever I update the database using raw sql code I have to manually host this file myself in SQL Server Management Studio (I then detach the database and leave the rest to visual studio). The server appears in the Visual Studio server explorer but Visual Studio cannot connect to it to run SQL code. Where is Visual Studio hosting this file so that the application can get to the database but the IDE can't?
Profiling: I have created some stored procedures for entity framework and mapped them to the entities. It would be really nice to see if these entities are actually being executed. How can I see the stored procedures executing with a tool like SQL Profiler?
Here are some screenshots in case what I am saying isn't clear:
SQL Server Management Studio:
Visual Studio Server Explorer:
As you see your connectionstring contains this part:
data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Database.mdf;
This means that it will take the file Database.mdf stored in your |DataDirectory| (which defaults to App_Data folder in web projects) and it will attach it dinamically to the provided sqlexpress instance (in this case .\sqlexpress which means the sqlexpress instance running on localhost .\ named sqlexpress.