Connection error with database .MDF C # Visual Studio

0

App.Config

<connectionStrings>
    <add name="conn"
        connectionString="Data Source=.\SQLExpress;AttachDbFilename=C:\Sistema\Sistema.mdf;Integrated Security=True"
        providerName="System.Data.SqlClient" />
</connectionStrings>

Error following

System.Data.SqlClient.SqlException (0x80131904): O banco de dados 
'C:\SISTEMA\SISTEMA.MDF' não pode ser aberto porque sua versão é a 869.
 Este servidor suporta a versão 782 e anteriores. O caminho de desatualização não é suportado.
Não foi possível abrir o novo banco de dados 'C:\SISTEMA\SISTEMA.MDF'. CREATE DATABASE foi anulado.
Falha na tentativa de anexar um banco de dados autodenominado no arquivo F:\Sisgemp\Sisgemp.mdf. Existe um banco de dados com o mesmo nome, o arquivo especificado não pode ser aberto, ou está localizado em um compartilhamento UNC.
   em System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   em System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   em System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   em System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   em System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   em System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   em System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource'1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   em System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource'1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   em System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource'1 retry, DbConnectionOptions userOptions)
   em System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource'1 retry, DbConnectionOptions userOptions)
   em System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource'1 retry)
   em System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource'1 retry)
   em System.Data.SqlClient.SqlConnection.Open()
   em WindowsFormsApp1.formLogin.acessar_Click(Object sender, EventArgs e) na C:\Sisgemp\formLogin.cs:linha 50
   em System.Windows.Forms.Control.OnClick(EventArgs e)
   em System.Windows.Forms.Button.OnClick(EventArgs e)
   em System.Windows.Forms.Button.PerformClick()
   em System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
   em System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
   em System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   em System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   em System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
ClientConnectionId:5f545993-bd51-42bf-870b-e3af757265b7
Error Number:948,State:1,Class:20
    
asked by anonymous 25.05.2018 / 01:03

2 answers

1

Sql Server version, I changed from 2012 to 2014 and it worked, I also set an adjustment on the LocalDB connection for. \ SQLExpress

    
29.05.2018 / 05:05
0

Version 782 is a database file of Sql Server 2014, version 706 is a database file of Sql Server 2012, it looks like you are trying a database of a newer version of the database file (SQL Server 2014) to an older version (SQL Serevr 2012 Express). As far as I know, SQL Server 2012 LocalDB will no longer be able to use these databases already upgraded to SQL Server 2014 LocalDB.

Reference: link

    
25.05.2018 / 22:53