You might be participating in a project that uses MS SQL Server 2008 R2 to connect to a database. It uses ADO.NET Entity Framework. I use Visual studio 2010 and WPF.
I have instaled SQL SERVER 2005 Express.

I got the project and i noticed that when i compile and run then: compilation is ok, but when i start my program i got exception xaml parse exception whitch have inner exception:

{"The database 'E:\\INFORMATYKA-STUDIA\\SEM 5\\DOT NET\\PROJEKT\\PROJEKT1\\GYT\\GYT.WPF\\BIN\\DEBUG\\GYT.MDF'cannot be opened because it is version 661. This server supports version 612 and earlier. A downgrade path is not supported.\r\nCould not open new database 'E:\\INFORMATYKA-STUDIA\\SEM 5\\DOT NET\\PROJEKT\\PROJEKT1\\GYT\\GYT.WPF\\BIN\\DEBUG\\GYT.MDF'. CREATE DATABASE is aborted.\r\nAn attempt to attach an auto-named database for file E:\\Informatyka-studia\\sem 5\\Dot Net\\projekt\\projekt1\\GYT\\GYT.WPF\\bin\\Debug\\gyt.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."}

This same exception i got when i wanted to conect database from visual studio.

So:

I found that version 612 is from SQL 2005 and version 661 is from SQL 2008R2.

I have instaled MS SQL 2008R2. I changed "SQL instance name"(Tools->options->Database options->Data Connections) to that name I choosed when I was instaling SQL server 2008R2. And since then i can connect database (view tables etc.) from visual studio.
But still when i compile and run program i get this same exception.

{"The database 'E:\\INFORMATYKA-STUDIA\\SEM 5\\DOT NET\\PROJEKT\\PROJEKT1\\GYT\\GYT.WPF\\BIN\\DEBUG\\GYT.MDF'cannot be opened because it is version 661. This server supports version 612 and earlier. A downgrade path is not supported.\r\nCould not open new database 'E:\\INFORMATYKA-STUDIA\\SEM 5\\DOT NET\\PROJEKT\\PROJEKT1\\GYT\\GYT.WPF\\BIN\\DEBUG\\GYT.MDF'. CREATE DATABASE is aborted.\r\nAn attempt to attach an auto-named database for file E:\\Informatyka-studia\\sem 5\\Dot Net\\projekt\\projekt1\\GYT\\GYT.WPF\\bin\\Debug\\gyt.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."}

So I checked services (start-> run-> Services.msc) and i stoped SQLEXPRESS service (2005 instance).
I got diffrent inner exception:

{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"}

So my conclusion is that my visual studio use SQL SERVER EXPRESS 2008R2 when i want to connect database in visual studio and see tables, views etc.
But it use SQL EXPRESS 2005 in compiled program. How to make my program to use SQL 2008R2?

Images of exception ( when SQL EXPRESS (2005) service is running):

click view detail:

Exception detail:

System.Windows.Markup.XamlParseException was unhandled
Message='The invocation of the constructor on type 'GYT.WPF.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
Source=PresentationFramework
LineNumber=3
LinePosition=9
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__1(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at GYT.WPF.App.Main() in E:\Informatyka-studia\sem 5\Dot Net\projekt\projekt1\GYT\GYT.WPF\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.EntityException
Message=The underlying provider failed on Open.
Source=System.Data.Entity
StackTrace:
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at GYT.Business.Repositories.UserRepository.GetAll() in E:\Informatyka-studia\sem 5\Dot Net\projekt\projekt1\GYT\GYT.Business\Repositories\UserRepository.cs:line 68
at GYT.WPF.MainWindow.RefreshUserListBox() in E:\Informatyka-studia\sem 5\Dot Net\projekt\projekt1\GYT\GYT.WPF\MainWindow.xaml.cs:line 62
at GYT.WPF.MainWindow..ctor() in E:\Informatyka-studia\sem 5\Dot Net\projekt\projekt1\GYT\GYT.WPF\MainWindow.xaml.cs:line 37
InnerException: System.Data.SqlClient.SqlException
Message=The database 'E:\INFORMATYKA-STUDIA\SEM 5\DOT NET\PROJEKT\PROJEKT1\GYT\GYT.WPF\BIN\DEBUG\GYT.MDF' cannot be opened because it is version 661. This server supports version 612 and earlier. A downgrade path is not supported.
Could not open new database 'E:\INFORMATYKA-STUDIA\SEM 5\DOT NET\PROJEKT\PROJEKT1\GYT\GYT.WPF\BIN\DEBUG\GYT.MDF'. CREATE DATABASE is aborted.
An attempt to attach an auto-named database for file E:\Informatyka-studia\sem 5\Dot Net\projekt\projekt1\GYT\GYT.WPF\bin\Debug\gyt.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=20
LineNumber=65536
Number=948
Procedure=""
Server=\\.\pipe\5132DEF3-2E6F-46\tsql\query
State=1
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
InnerException:

Please help! or ask for more details (but i dont know what also can be useful- so explain what you need) .

How to resolve the problem:

  1. Go to the App.Config file ( in my Solution there are 2 files with that name - each one in database project and in WPF project). There are xml files.
  2. Find <conectionStrings> section
  3. Find "Data Source" atribute and change value from .\SQLEXPRESS (name of my SQL SERVER 2005 service)
    to .\SQLSERVERE2008R2 (name of my SQL SERVER 2008 R2 service)
  4. Do it in your all App.Config files.

it look like this:

<connectionStrings

>

<addname="gytEntities"connectionString="metadata=res://*/GYTModel.csdl|res://*/GYTModel.ssdl|res://*/GYTModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLSERVERE2008R2;AttachDbFilename=|DataDirectory|\gyt.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;"providerName="System.Data.EntityClient"/>

</connectionStrings

>

  1. Start
  2. Run program
  3. type: Services.msc
  4. find SQL SERVER
  5. I have 2 lines with this prefix :

SQL Server (SQLEXPRESS)
SQL Server (SQLSERVERE2008R2)

Text in brackets are names of SQL SERVER instances.





Notice that you can have different names. If you dont know what your SQLSERVER instance name is "do:" 
 
This article is sourced from here:
http://social.microsoft.com/Forums/en-US/whatforum/thread/6804bad2-586d-4375-bb2c-7697690c860d