2013-05-02 235 views
0

我正在使用新主機進行測試,並且遇到連接到數據庫的問題。嘗試連接到數據庫EF和SQL Server時出錯

我已經有同一個項目會在另一個主機和SQL Server 2005

但這個新的主機時,SQL Server 2012是運行並試圖獲得從數據庫中提取數據的頁面時,返回此錯誤:

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)

連接字符串:

<connectionStrings> 
    <add name="ERPContext" 
     connectionString="Data Source=SQL5003; Initial Catalog=DB_99C4E9;User Id=DB_99C4E9;Password=senha;" 
     providerName="System.Data.SqlClient" /> 
</connectionStrings> 

ERPContext:

public class ERPContextUser : DbContext 
    { 
     public DbSet<UsuarioAtivacao> UsuarioAtivacao { get; set; } 

     public ERPContextUser() : base("ConexaoERP") 
     { 
      Database.SetInitializer<ERPContextUser>(null); 
     } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      modelBuilder.Entity<UsuarioAtivacao>().ToTable("Usuario"); 
     } 
    } 

    public class ERPContext : DbContext 
    { 
     public DbSet<Empresa> Empresa { get; set; } 
     public DbSet<Pessoa> Pessoa { get; set; } 
     public DbSet<Usuario> Usuario { get; set; } 
     public DbSet<UsuarioAcesso> UsuarioAcesso { get; set; } 
     public DbSet<SimNao> SimNao { get; set; }   
     public DbSet<Sexo> Sexo { get; set; } 
     public DbSet<TipoPessoa> TipoPessoa { get; set; } 
     public DbSet<UnidadeMedida> UnidadeMedida { get; set; } 

     public ERPContext() 
      : base("ConexaoERP") 
     { 
      Database.SetInitializer<ERPContext>(null); 
     } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      modelBuilder.Entity<Empresa>().ToTable("Empresa"); 
      modelBuilder.Entity<Pessoa>().ToTable("Pessoa");    
      modelBuilder.Entity<Usuario>().ToTable("Usuario"); 
      modelBuilder.Entity<UsuarioAcesso>().ToTable("UsuarioAcesso"); 
     } 
    } 
+0

你檢查服務器'SQL5003'(或合適的別名)存在,即SQL安裝爲一個默認實例服務器,並且該SQL配置爲允許遠程連接? – 2013-05-02 16:43:05

回答

1

似乎你需要在你的web.config名ERPContext改爲ConexaoERP

+0

tks ...不能查看錯誤... – 2013-05-02 16:36:38

相關問題