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.
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/
I am using C# WPF EF6.0 and SQL Server Express for final program.
I have created a setup file with Advanced installer that creates database via script and SQL Server Express in
C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA
and I have changed my string connection from
<add name="MyDBEntities"
connectionString="metadata=res://*/MyDBModel.csdl|res://*/MyDBModel.ssdl|res://*/MyDBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\MyDB.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
To this
<add name="MyDBEntities"
connectionString="metadata=res://*/MyDBModel.csdl|
res://*/MyDBModel.ssdl|
res://*/MyDBModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data source=.\SQLExpress;
integrated security=True;
MultipleActiveResultSets=True;
Initial Catalog=MyDB;
App=EntityFramework""
providerName="System.Data.EntityClient" />
I have installed .net Framework 4.5 and SQL Server 2012 sp1 v11.0.300 that I have used in Visual Studio 2013
When I install my program, everything works, but when I run my program it stopped working at first launch. I think the connection string has a problem.
If I click debug in Visual Studio, I see this error
An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll.Additional information: No connection string named 'MyDBEntities' could be found in the application config file.
The reason is that you have not attached the database files to the local database engine. try to use the appropriate SQL Server methods which are available. Your application (after installation) can not find the database in the local DB engine.
Finally I couldn't create a setup file with Advanced Installer.
But I created it by Install Shield.
My problem was insert or delete or edit from database.
I installed my program in other drive and my problem solved.
The reason was a joke that program files in C is readonly.
This question already has answers here:
How to connect to a MySQL Data Source in Visual Studio
(13 answers)
Closed 6 years ago.
I currently run a PHP website which uses MYSQL for the database but now I what to move the website to MVC .Net environment but can't figure out how to this is what I am trying:
I Installed MYSQL.data.Entity, EF, and Web through Nuget package
then I added the connection string in the web.config file:
<connectionStrings>
<add name="constr" connectionString="Data Source=localhost;Initial Catalog=SampleDB;User Id=root;password=''"/>
</connectionStrings>
Password is left empty because there is no password on the database as I running it locally to test it
after all that I still cant view the Database I Server Explorer? should I be able to view the database in server explorer?
How can I make it work?
(also note I took the live database and put it into local)
You are not mentioning the mySql Connector for .NET. https://dev.mysql.com/downloads/connector/net/
Install it and it should start working ;)
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?
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>