Problems connecting to sql server with Visual Studio and C#

Asked

Viewed 759 times

0

I have encountered problems connecting to sql server by visual studio with Entity Framework 6. My connection worked normally and after I created a new project, I cannot access the database server. The service works normally.

Serviços do sql server ativos

My connection string is always giving error stating that the Initial Catalog keyword is not supported. I have already done the removal of this parameter and realized that everything that is after Data Source is considered as unsupported keyword.

public DataContext() : base("Data Source=localhost/sqlexpress;Initial Catalog=DocManager;User Id=sa;Password=123456; Integrated Security=false;")
    {

    }

Firewall is disabled to prevent port locking issues.

Firewall Inativo

As an alternative I tried to make the connection by the server manager tool of Visual Studio itself, but to my disappointment, I can not make any connection from there and my server is not listed for connection.

Gerenciador de servidores não faz conexão

Any suggestions that might help me solve this problem?


The exceptions I get are these:

  1. Keyword not supported: 'initial Catalog'.
  2. Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: Named Pipes Provider, error: 40 - Unable to open connection to SQL Server)

However the server is running. I have checked the server name and everything checks out.

  • When you run the project generates some exception? If yes, could you add her to the question?

  • Keyword not supported: 'initial Catalog'. Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: Named Pipes Provider, error: 40 - Unable to open connection to SQL Server)

2 answers

1

At the url Data Source use the slider backwards \.

// Nào esqueça de usar a sequencia de escape \\
public DataContext() : base("Data Source=localhost\\SQLEXPRESS;Initial Catalog=DocManager;User Id=sa;Password=123456; Integrated Security=false;")
{

}

-2

I removed the login data and left Integrated Security as true and it operated normally(as it is only test environment I left as true):


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) //Método de configuração do Entity, nos informa qual banco de dados usaremos
        {
            //String de conexão
            optionsBuilder.UseSqlServer("Data Source=localhost\\SQLEXPRESS;Initial Catalog=DocManager;Integrated Security=true");
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.