Problem with users when publishing application

1

I'm using SQL Server 2012, and when I publish my application, both on the client server and on my pc everything works fine. The connection strings for DB is correct, everything looks fine. Now where's the problem? When trying to authenticate a user I get the error:

  

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: 50 - Local Database Runtime error occurred.   )

In my AuthConfig.cs I have:

WebSecurity.InitializeDatabaseConnection("Server=" + ConfigurationManager.AppSettings["Server"] + ";Database=" + ConfigurationManager.AppSettings["Database"] + ";Integrated Security=False;User ID=" + ConfigurationManager.AppSettings["UserID"] + ";Password=" + ConfigurationManager.AppSettings["Password"] + ";MultipleActiveResultSets=true;",
                        "System.Data.SqlClient", "Users", "UserId", "UserName", autoCreateTables: true);

Where do I get the Data ( Server , Database , UserID and Password ) from my Web.config

Web.config :

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcTesteLayout-20131023143453;Integrated Security=False;AttachDBFilename=|DataDirectory|\aspnet-MvcTesteLayout-20131023143453.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="Server" value="CPSI0024\SQLEXPRESS" />
    <add key="Database" value="OleoTorres" />
    <add key="UserID" value="OleoTorres" />
    <add key="Password" value="oleotorres" />
    <add key="ServerArtSoft" value="OLEOTORRES2014" />
    <add key="UserServerArtSoft" value="Admin" />
    <add key="PassServerArtSoft" value="passServ" />
    <add key="pathFiles" value="D:/uploadsOleotorres"></add>
    <add key="pathFilesGerarPDF" value="D:/gerarPDFOleotorres"></add>
  </appSettings>

I've already tried several ways to solve it, but I could not find a solution where I could solve the problem ...

    
asked by anonymous 04.04.2014 / 17:57

3 answers

0

Well, after a good few hours back from this problem I found the solution. I commented my connectionString on web.config :

  <connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcTesteLayout-20131023143453;Integrated Security=False;AttachDBFilename=|DataDirectory|\aspnet-MvcTesteLayout-20131023143453.mdf" providerName="System.Data.SqlClient" />-->

And I deleted the InitializeSimpleMembershipAttribute.cs file when creating the project in Visual Studio.

It seems to me, he was logging into a database called localDb instead of being in my CPSI0024 \ SQLEXPRESS . Until now I thought that using localDb was referring to CPSI0024 \ SQLEXPRESS and not to a local database apart ...

Still, thanks for your answers:)

    
08.04.2014 / 11:29
1

What is the version of Sql Server? Will it be 'LocalDb'? And what is the format of the 'Server' value in web.config? (do not write your own name here, use a fictitious name). Is this local or remote?

If you have 'Sql Server Management Studio' (SSMS) you can open, right click on the node above that represents the DB, choose 'Properties / Connections', and see a' Allow remote connections to this server "- this needs to be checked.

A suggestion on the side. If you write the complete connectionString in web.config inside the section "connectionStrings" then it is clearer to simply search with ConfigurationManager.ConnectionStrings[chave].ConnectionString

    
06.04.2014 / 10:17
1

If the database is on a separate machine (as suggested by the CPSI0024 machine) using a SQL Server Express instance, additional configuration is required to allow remote connections:

  • Start > All Programs > Microsoft SQL Server (version) > SQL Server Configuration Manager (as administrator);
  • Expand SQL Server Network Configuration ;
  • Click Protocols ;
  • Enable TCP / IP . Optionally, enable Named Pipes as well.
  • Also check that the Firewall is enabled to allow Inbound and Outbound Connections for the instance of SQL Server.

        
    07.04.2014 / 19:17