I have an N-Tier MVC4 project connected to an SQL server database.
The MVC4 project was created using the MVC internet application template in VS.
I'm trying to deploy this project to windows azure.
The website was added to azure with no problems the database was added with no problem as well.
When i browse to my website it's there but when i try to do actions related to the DB such as register/login/view a certain list 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."
my development connection string is:
<add name="CarRentalDataBaseEntities" connectionString="metadata=res://*/CarRentalDataBase.csdl|res://*/CarRentalDataBase.ssdl|res://*/CarRentalDataBase.msl;provider=System.Data.SqlClient;provider connection string="data source=CONSTANTINE-PC\SQLEXPRESS;initial catalog=CarRentalDataBase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
my production connection string is:
<add name="CarRentalDataBaseEntities" connectionString="metadata=res://*/CarRentalDataBase.csdl|res://*/CarRentalDataBase.ssdl|res://*/CarRentalDataBase.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:ptuwjgqh7p.database.windows.net,1433;Database=CarRentalDataBase;User ID=XXXX;Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
when i run the project in VS it works fine with no problems, which means that remote connections allowed to the database.
Seems that there something wrong with the connection between the website and the database in azure but i dont know what.
please advise what can i check in order to find the problem.
Thank you.
EDIT:
I just created draft MVC website that has a connection to a database and it worked - There is a connection to the DB in azure.
The difference was that this website wasnt N-Tier designed meaning it didnt have a business logic project.
In my original website (the one that i still didnt manage to connect to a DB) there is a business logic project and the database edmx file is on that project.
The publish to azure that i did was to the MVC website project that has a reference to the business logic(which has the edmx DB file).
Any suggestions on the latest findings?
Thank you.
Eventually I found that in the publish menu, in Settings under databases, from some reason, the connection string did not match the connection string in AppConfig and Azure management portal all though I performed a Clean-Rebuild on the entire solution before publishing.. Anyway mystery solved after almost a year!
On the firewall section of the portal for that server have you turned on access to Azure Services?
Related
I write a small ASP.NET web application with a controller that can access to my local db to retrive informations. When I start the application from visual studio everything works fine, but when I publish the application to IIS I get this error:
"An error has occurred.","exceptionMessage":"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. Cannot create an automatic instance."
I can't understand why the application works from visual studio but fails after the publish. My connection strings (automatically generated when I create the controller with EntityFramework) are :
<connectionStrings>
<add name="ToDoContext" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=ToDoContext-20190205170505; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|ToDoContext-20190205170505.mdf"
providerName="System.Data.SqlClient" />
I noticed that when I run the application form VS in the Url there is the port number, meanwhile from IIS there isn't (I don't know if this fact could have any impact). Any suggestions? Thank you.
This connection string is pointing to an instance of LocalDb. It is highly unlikely that you have this installed on the server, hence getting the connection error.
You need to find out what SQL server instances are available to your IIS application. In a staging or QA environment it might just be localhost but in production it is likely to be separate server.
It is also unlikely that Integrated Security will work (and probably shouldn't be made to work). You need to obtain a username and password from the DBA and use that.
Because you are using integrated security, make sure the applicationpoolidentity used by IIS is setup for SQL Server as per here: https://blogs.msdn.microsoft.com/ericparvin/2015/04/14/how-to-add-the-applicationpoolidentity-to-a-sql-server-login/
This question already has an answer here:
appharbor connection string
(1 answer)
Closed 7 years ago.
I am using asp.net identity with EF data first approach. Everything is working fine on localhost. I have hosted my website on appharbor. All of my controllers actions and webapi is working fine except AccountController. When a user tries to signup it gives the Internal server error. The details of error is:
Note: My database queries are working fine. It means there is no issue in connection string.
And to enable remote connections SQL Server Network Configuration does not has the option Protocols for SQLEXPRESS
How can I tackle this issue?
Update:
My connection strings in web.config are:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Inspinia_MVC5_SeedProject-20141215093835.mdf;Initial Catalog=aspnet-Inspinia_MVC5_SeedProject-20141215093835;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=b1ad1f3e-1ab5-4169-93f8-a5ae006f3e4e.sqlserver.sequelizer.com;Database=8a5ae006f3e4e;User ID=namucclqps;Password=54nWBkCfURyMzYfhbu8NUQb6PEZUsWcoN;"" providerName="System.Data.EntityClient" />
</connectionStrings>
Update 2:
I installed SQL Server Management Studio. Then I hosted my website on appharbor and installed add-on SQL Server. Then using following info I connected to Server.
Then added tables in SQL Server Management Studio and changed connection string in web.config and published website.
LocalDB is only a thing inside Visual Studio. There's no way to even get it on a production server. You need to install some version of SQL Server and then create your database and tables there.
After that, leave the original connection string inside Web.config alone, and instead, add a transform in Web.Release.config that changes the connection string to the one for your production SQL Server instance of your database. Finally, when publishing your site, select the "Release" configuration. The Web.config will then be transformed during publishing and will reference the production database once the site is deployed.
More of the exception
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Cannot open database "BotDb" requested by the login. The login failed.
Login failed for user 'PIXELBOT\pixelbot'.
Hello
I made a console applicaiton in C# which uses a database with Entity framework.
The program works just fine on my own computer, but i need the program to run 24/7, so i rented a VPS through azure.
The problem is, that the program is not working on the VPS. The VPS is all new, and totally clean. The only thing i installed is Microsoft SQL Server 2014 LocalDB Express 64 Bit. I get the exception in the top of this post.
I really have no clue whats wrong, or what i should try to do. I've been searching around, and found other threads with problems like this, but none of the solutions work so far.
My connectionstring in the program if that is relevant:
<add name="BotDb"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=BotDb;User Id="usernameonvps";Password="passwordtovps";Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
Do you check MSSQL settings? Is the SQL Server authentication switched on? May be server allows Windows authentication only.
Fairly simple question about connection strings using an ASP.Net MVC web application with a SQL server Database.
I created a Web application which uses a database, using the default templates for an MVC 5 application using Visual studio 2014.
I am moving my application over to a IIS and sql server express database (2014) and I see that the database my application uses is a localDB (has a .mdf extension) what I need to know is how to attach it to my SQL Server Express database. (The development Machine and the Server are separate machines)
I have attached it to the server and have a login "IIS APPPOOL\DefaultAppPool" for my IIS to be able to use the server. Here I have granted the login read and write permission to the database "aspnet-owinTest-20140519094353" and my connection string in IIS is
Server=KEVIN-PC\SQLEXPRESS;Database=aspnet-owinTest-20140519094353;Integrated Security=true
The default connection string when building my application is:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-owinTest-20140519094353.mdf;Initial Catalog=aspnet-owinTest-20140519094353;Integrated Security=True" providerName="System.Data.SqlClient" />
If anyone can please give me a hand with this. My application simply throws an error
Error.
An error occurred while processing your request.
This is the default MVC error.
Also are there any ways where I can see what happened? As in a log of sorts, I checked in the IIS log and there did not seem to be any information that would help me. Would it be better for me to just have a login that used a Username/Password rather than using Windows Authentication?
I believe I found what I was looking for:
How to deploy ASP.NET MVC 4 application using localDB to local IIS on Windows 7?
This did the trick, though probably not a good idea for production server.
I guess one would have to do some type of restore on the SQL server from the .mdf.
All one has to do is publish their files, drop them in the wwwroot folder (along with the app_data folder containing your database and logs) and set the pool to local and you should be set.
If you are quite new to Visual Studio and facing this error, the very first thing I would suggest to check is INCLUDE all the files from the project. If there are some dependent folders or files which are left as excluded, this very error message is thrown back to browser.
To do this, first click on the icon of "Show All Files" and check for any of the expected files which you created/added but didn't include in the project. If you find one, then right click and include it.
If there is any quicker way to identify/avoid any such excluded files/folders issues, then please share below in comments.
I'm currently setting up two websites using one web role on Windows Azure. When I deploy the sites to Azure they deploy successfully, but I get a warning:
Warning 1 The connection string 'DefaultConnection' is using a local database
'(LocalDb)\v11.0' in project 'GTCompanySite'. This connection string will not work when
you run this application in Windows Azure. To access a different database, you should
update the connection string in the web.config file.
I've attempted several solutions: I published the second website and referenced the physical path to the published folder. No luck. Both websites reference the default LocalDB, but also seem to correctly hook up to the Azure Storage service. I haven't messed with those settings at all.
Any pro-tips for solving this issue?
Regards,
Jesse
In a local environment it iss possible to connect your application to a Local SQL Server Express Instance.
However when you deploy to Azure you'll need to connect your app to an actual running SQL Server Instance. A SQL Azure Instance is probably your simplest option as you can easily spin one up through the Azure Management Portal. (Though you could also host a regular SQL Server Install on a VM)
Once you've created your SQL Azure Instance, you'll be provided with all the Connection and Auth credentials you need. You'll need to change the DefaultConnection connection string in your Application Configuration or CSCFG file depending on where your storing it to point at the new SQL Azure Instance, instead of a SQL Express before you deploy your app.
<configuration>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=tcp:[serverName].database.windows.net;
Database=myDataBase;
User ID=[LoginForDb]#[serverName];
Password=myPassword;
Trusted_Connection=False;
Encrypt=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>