Problem with users when publishing application

Asked

Viewed 435 times

1

I am using SQL Server 2012, and when publishing my application, both on the client server and on my pc everything works well. As connection strings for the BD are correct, everything looks good. Now where is 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. (Preview: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an Automatic instance. See the Windows Application Event log for error Details. )

In my file Authconfig.Cs 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 will I get the data (Server, Database, Userid and Password) to 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 looked for several ways to solve it, but I couldn’t find a solution to solve the problem...

  • This error means that the SQL Server instance was not found. You can put your file Web.config in the question?

  • @Ciganomorrisonmendez, edited

  • @Cesarmiguel, try to change your string Connection by pointing to the server’s IP or DNS, even if it is the machine itself. Check in your SQL Managment Studio which is the server name and use similar.

  • Yeah, but my server name in SQL Managment Studio is "CPSI0024 SQLEXPRESS", which is what I’m using

  • @Cesarmiguel Try to assemble the connectionString out of the call of the method InitializeDatabaseConnection and in debug check how to connectionString was mounted.

  • @Gypsy, I checked in debug and the name of connectionString is correct. I have the application working properly, only when I publish it, it stops the part of the users. Is there perhaps no option in SQL Server? Or is this error even pointing to bad webconfig configuration?

  • @Cesarmiguel Where its application is published?

  • Both on my machine (tests) and on the client server

Show 3 more comments

3 answers

1

If the database is on a separate machine (as the machine suggests CPSI0024) using an SQL Server Express instance, you need to make an additional configuration to allow remote connections:

  1. Initiate > All Programs > Microsoft SQL Server (version) > SQL Server Configuration Manager (as an administrator);
  2. Expand SQL Server Network Configuration;
  3. Click on Protocols;
  4. Enable the TCP/IP. Optionally, also enable Named Pipes.

Also check that Firewall is enabled to allow Inbound and Outbound Connections to the SQL Server instance.

  • That’s not the problem either. At least it didn’t solve

  • I have found the solution. I will publish

1

What is the version of Sql Server? Will it be 'Localdb'? And what is the format of the Server value on web.config? (do not write your own name here, use a dummy name). This location or remote?

If you have 'Sql Server Management Studio' (SSMS) you can open, right click on the node above that represents the BD, choose 'Properties/Connections', and see an option "Allow remote Connections to this server" - this must be marked.

A suggestion on the side. If you write the connectionString in full on the web.config within "connectionStrings" section then it will be sharper to search simply with ConfigurationManager.ConnectionStrings[chave].ConnectionString

inserir a descrição da imagem aqui

  • I can’t find the option "Allow remote Connections to this server". It’s in the properties of my BD (Oleotorres)?

  • I added a screenshot. I’m not sure if SQL Server Express allows connection outside the machine itself. But...looking at your web.config, the error seems to be trying to use the 'Defaultconnnection' string Connection...because of the phrase: "Local Database Runtime Error" and "Cannot create Automatic instance"...are talking about Localdb...so the problem may be more in the behavior of Websecurity first looking for a Localdb or maybe a Connection string "Defaultconnection"...do not know this library.

  • I have already checked. I’ll see what I can do in the string Connection

  • @Cesarmiguel Parace, according to the documentation Initializedatabaseconnection that the first Parameter is the name of key connectionString, not connectionString itself.... makes sense then, that the method does not find a connectionString with the name of this one (which is a boring string) and then tries to create a new BD in Localdb...

  • But then you shouldn’t work on the application at all (right?). And the only thing that’s not working for me is data that has to do with users like login, storing logged-in user data etc

  • Not necessarily. Websecurity only estabileça connecão with the safety tablets and users and papers. They are usually pre-configured by ASP.Net Identity services regardless of the logic of the rest of the application. It can even require a second connectionString just for that. And if you don’t find the tabs, try creating them in a comic book of your own, sometimes on Localdb, which seems to be happening here.

Show 1 more comment

0


Well, after a few hours back from this problem I found the solution. I commented on my connectionString in the 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 file Initializesimplemembershipattribute.Cs that when creating the project in Visual studio.

As far as I can tell, he was logging into a database called localDb instead of being in mine CPSI0024 SQLEXPRESS. Until now I thought that by using the localDb was making reference to CPSI0024 SQLEXPRESS and not a separate local database...

Nevertheless, thank you for your replies :)

  • Alternatively, you can set up your connectionString thus: <add name="DefaultConnection" connectionString="Data Source=CPSI0024\SQLEXPRESS;Integrated Security=False;User ID=seuusuario;Password=senha" providerName="System.Data.SqlClient" />

Browser other questions tagged

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