the following error appears when I want to launch the Security tab in ASP .NET Configuration site for my ASP NET MVC 4 project:
http://s14.postimg.org/jvizqragv/error_sql.png
I know that there are a lot of questions related to that error, but i tried a lot of the tips for solving this (I tried the suggested solutions here - http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx but the error is still here).
But let me explain what are my databases in the solution. I have a local database (an .MDF file in App_Data) and a database for users authentication which was generated by ASP NET MVC. They are all placed in the App_Data folder as I'm trying to work on this solution on different machines. The strange thing is that on my laptop at home there is no such problem - I am able to create roles, explore users and all the functionality in the Security tab and I think there might be some problem with the SQL Server on my desktop machine - I use the Express edition on my laptop and the Developer edition on the other machine where things don't work.
My connection strings are the following:
<add name="FootballTransfers20130717145140Context" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\FootballTransfers.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DefaultConnection.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
The first one is for the Entity framework and is related to the database where I store my application specific data. The second one is for the users administration database generated by SQL. Without the second connection string I'm not able to open any action of the Account controller.
It's very strange because it works on one machine and not on another. I was wondering if there's something wrong with the connection string, but I guess there's something with the SQL Server. As I said I tried various solutions but they didn't work.
LocalDB is a feature of SQL Server Express only. You will have to install SQL Server Express on the machine or import your database to your SQL Server and change your connection strings.
In production, you would probably have to move to a full SQL Server edition anyway.
I added the roles i was trying to make in code in the AccountController and now I'm able to register users with roles, but the problem that appeared now is that when I put the Authorize attribute on some action so that only users with certain roles can request them, the following error appears:
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)
When I remove the attribute so anyone can access it, the action works fine. I found some article on the net saying that providers must be specified in the config, but some errors kept appearing that those tags are unknown.
Related
I have a web application in visual studio 2017 .NET framework 4.7.1 with identity, that connects to azure sql server database. I am getting an error after submitting login form. The exception message is:
"Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net). Some libraries do not send the server name, in which case the server name must be included as part of the user name (username#servername). In addition, if both formats are used, the server names must match."
The error is only in the web server (azure app service). When I run it locally (localhost) it works fine.
I did what error message suggests but, it did´nt work. I searched about this but, none of the suggestions or solutions I found have worked.
If I remove login stuff, application is able to connect and works so, the problem seems to be the connection string I use to connect to identity tables.
I have tried this connection strings in web.config but none of them have worked:
1.
add name="DefaultConnection" connectionString="Server=tcp:myServer.database.windows.net,1433;Initial Catalog=myDatabase;Persist Security Info=False;User ID=myUser#myServer;Password=myPassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False" providerName="System.Data.SqlClient"
2.
add name="DefaultConnection" connectionString="Data Source=myServer.database.windows.net;Initial Catalog=myDatabase;Integrated Security=False;User Id=myUser;Password=myPassword;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"
First, did you set the Allow access to Azrue Service ON?
Please check your Azrue SQL Database firewall settings on portal:
Second, get the correct connection string:
Others, please see: Troubleshooting connectivity issues with Microsoft Azure SQL Database.
Hope this can helps.
Long story but I have a web app that has a SQL Server DB that works fine but also has a ASPNETDB.MDF database (for membership), which has always worked fine under SQL Server 2008. I did an upgrade on the server to SQL Server 2014 and I can no longer access the ASPNETDB.MDF database and get this error:
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)
I've modified the connection string to update to what is expected with 2014 and that works fine in a simple console app (I can connect, run SQL commands, etc.) But I have not been able to figure out why I can make it work in production. NOTE: it doesn't even work in a browser on the web server - I get the same error.
Here is my connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Trusted_Connection=Yes" />
I think it's possible... but really, you'll do much better installing Sql Server Express Edition on that machine, and then attaching the mdf file to the Express instance.
You'll also need some work to setup security and a few other things, but this puts you back into a more "normal" or typical deployment scenario for a web database. This will also make it much easier to troubleshoot the kind of error seen in the question.
It maybe your Remote Connection is not enabled on Server Side.
You have to make sure that it is enabled.
Here's you some guide1 and guide2 to make it Done
A network-related or instance-specific error occurred while establishing a connection to SQL Server
The main page loads fine, but the error occurs when I try to goto Account/Register or Account/Login.
The error occurs on this line in SimpleMembershipInitializer constructor in file Filters/InitializeSimpleMembershipAttribute.cs
if (!context.Database.Exists())
Now, if I set my web.config to
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />
</entityFramework>
it works locally only but I'm assuming it's using a local database. Right now my entity framework in the web.config looks like
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
I have another application where I am using the same hosting service and free database (appharbor and SQL Server Yocto) and it works just fine. I recently setup a new application and database and it doesn't work. I can connect to the database fine in SQL server and expanding the DataConnections -> MyContextName in visual studio 2012, so I know the connection string is not the problem.
I'm wondering if there is a problem on the server the database is hosted on and I don't have access to that.
I'm all out of ideas on how to fix this problem. Thanks.
The problem probably is that the connection string name hasn't been configured properly and/or doesn't follow the entity framework conventions (which differs a bit between Entity framework versions). If you can connect to the database from your own machine or from the SQL server admin page the problem is unlikely to be related to the database/database server itself.
Take a look at this discussion where another user experienced a similar issue. You might just need to set the right connection string name for the entity framework database context. Also make sure you have migrations set up to create the database.
This may explain why it's working locally with the local db connection factory. I suspect that a database is created in your local SQL server, and it can do so unrestricted. On AppHarbor you need to use the database and connection string provided since you can't create databases yourself. You can confirm whether that's the case by connecting to your local database server and listing the available databases.
I can also recommend using this sample application and the associated blog posts about running migrations and configuring entity framework (4.3) on AppHarbor.
I created an MVC4 solution in VS 2012 with EF5, and right now I am trying to get the database to be created Code First. In the Create method of the controller I added db.Database.CreateIfNotExists();
On my machine, I also have SQL Server 2012 running, and I would like the db to be created there instead of in some SQL Express engine or other lightweight solution.
I have tried several approaches to making a correct connection string, but all has failed, and now I have no idea as to how it should look. This is how it looks now, but nothing gets created, and all i get from the CreateIfNotExists is an error:
InnerException {"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"} System.Exception {System.Data.SqlClient.SqlException}
This is what my connection string looks like:
<add name="Tool.Models.Context" connectionString="Server=MSSQLSERVER;Initial Catalog=Tool.models.ToolDb.mdf;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
EDIT:
After struggling with this issue for almost a day, I resolved it by substituting localhost for MSSQLSERVER (Which still is the name of the instance if I look at the Configuration Manager). Thanks for the comments though. Made me think.
localhost is the local server, not the instance, you appear to be using the default instance (called mssqlserver) and so don't need to specify the instance name, just the server name, hence why substituting MSSQLSERVER with localhost in your connection string works.
You could also use the actual name of the server in here, e.g. SERVER-01 (or whatever the actual name of your particular DB server is) and it would have the same effect.
If however you had installed a named instance on the machine, you would have to specify both the server name and the instance, e.g. localhost\instancename or server-01\instancename
Hope this helps explain why putting in localhost works.
That's right...
By default, as most may already be aware, Visual Studio 2012 - ASP.NET MVC 4 templates
will define a Default connectionString that points to a (LocalDb)v11.0 in Web.config.
In the case of Visual Studio 2010 ASP.Net MVC 4 project templates, it pointed to SQLExpress...
In my case I prefer pointing the connectionString to a specific SQL Server 2012 I use for dev.
So let's say I open SQL Management Studio and see SQLServer2012-01 name in a droplist where I want the database + tables to be created,
well that's the name I'd normally use...
connectionString="Server=SQLServer2012-01; InitialCatalog=..."
All you have to do afterwards is straightforward - follow the steps in defining
-Enable-Migrations
-[fill your Seed method with content - if needed...]
-Add-Migration MyFirstMigration [or any migration name you want]
-Update-Database -Verbose
and you should see results updated in Server Explorer Window.
Hope it helps
I'm trying to get a very simply EF Code First example running but ran into the above problem. I've followed the advice here ( How to configure ProviderManifestToken for EF Code First ) but to no avail. I finally managed to get EF to create my database and tables by passing the actual connection string to the DBContext instead of the connection string name I had defined.
Here is how I defined by connection string initially in app.config
<connectionStrings>
<add name="ProductContext"
connectionString="integrated security=SSPI;
data source=MYMACHINE;
persist security info=False;
initial catalog=Product"
providerName="System.Data.SqlClient" />
</connectionStrings>
The name "ProductContext" matches the class ProductContext and the database Product does not exist.
Following the advice on a previous thread I passed the connection string name to ProductContext and the base DBContext cstor. This did not work either.
Finally, I passed the connection string above instead and everything worked, the db was created and the tables.
I'm using SQL Server 2008 and EF 4.1. Any ideas as to what I'm doing wrong?
Thanks,
Ken
Update
The application is a WPF application, not a web application. I get the same exception after I remove the connectionstring from app.config:
"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)"
The problem with answering this question is that the culprit could be more than one issue.
That said, I see a couple things to check:
Your Data Source name looks to be invalid. You need to declare the host name and the instance name. Example: .\SQLEXPRESS (notice the . dot) or MyServerHostName\MySqlInstanceName.
Verify you have a valid data source by using SQL Server Management Studio and trying it there first.
Permissions. You are using integrated security and so the security context of the application making the database connection must have proper rights. Things to check:
Using SQL Server Mgmt Studio, connect to your database. Select your database in the left pane (Object Explorer) --> Databases --> Select your db --> Security --> Users. Make sure you can verify the account being used to run the app has either been granted rights explicitly or can inherit them by being a member of the groups.
When I had this error, my problem proved to be that I had mixed Integrated Security=SSPI with a "Username =" and "Password =" ...not realizing that I needed Integrated Security=false; my user and password parameters were being ignored.
Not sure about this one: I did read some people suggest (at least for troubleshooting) to set Persist Security Info=true.
I had similar problem on EF6 VS 2013, the problem got solved, when I choose 'Save Password' on Entity Framework - Reverse Engineer Code First - Connection Properties Dialog. Hope this helps someone.