This is my first MVC Website with a database hosted on Azure.
I have deployed the database and the website. However I get an Access Denied error message:
[SqlException (0x80131904): 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)]
What I don't get is that I can run the app via Visual Studio connected via the Azure connection string locally without any problems. I can speak to the db remotely but not within Azure!!!
Here's the connection string I'm using:
<connectionStrings>
<add name="myConnString"
connectionString="metadata=res://*/Models.MyModel.csdl|res://*/Models.MyModel.ssdl|res://*/Models.MyModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source = tcp:mybdurl.database.windows.net,1433;Initial Catalog=myDb;
persist security info=True;
User ID=MyId;
Password=MyPassword;
MultipleActiveResultSets=True;
application name=EntityFramework""
providerName="System.Data.EntityClient"
/>
</connectionStrings>
I'm guessing there is a missing magic Azure element that allows access. Both are in the same data centre and within the same account.
Cheers
I was publishing the web.config file individually in Visual Studio, not realising it wasn't actually updating on Azure. I went back to old fashioned FTP and indeed the live web.config was still the original not the one for Azure.
Manually uploaded it and it worked!
What didn't it publish???
Related
I am using I am using Visual Studio 2017. I just created a brand new mdf file in my project (Right click on App Data -> Add New Item -> SQL Server Database) and I called the file TestDatabase.mdf
Now I am trying to connect to it via a connection string:
<add name="TestConnection" connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|TestDatabase.mdf;Database=TestDatabase; Trusted_Connection=Yes;" providerName="System.Data.SqlClient" />
Next I created a Model and then Created a EntityFramework Controller, but now when I goto the controller index method I get this 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: 26 - Error Locating Server/Instance
Specified)
What am I doing wrong?
Make sure you testDatabase.mdf available in App_Data folder.
<connectionStrings>
<add name="ConnectionName"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
This connection string that you have written is incorrect.
<add name="TestConnection" connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|TestDatabase.mdf;Database=TestDatabase; Trusted_Connection=Yes;" providerName="System.Data.SqlClient" />
I assume that you have SQL Express installed in your system. This will provide a local instance of SQL to run on your machine.
As you said you are using Visual Studio 2017, you can follow these steps to get the correct connection string
Open Server Explorer
Right Click on your Database and click Properties
A property window will open, copy the ConnectionString and make sure it looks like this:
<add name="YourDbName" connectionString="Data Source=YourComputerName\SQLEXPRESS;Initial Catalog=YourDbName;Integrated Security=True" />
And now talking about this:
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)
You are getting this error because it is not getting the instance name to connect to the database. In my example, SQLEXPRESS serves as an instance name. If you don't have SQLEXPRESS you can download it from here:
https://www.microsoft.com/en-in/sql-server/sql-server-editions-express
You can follow the prompt and install this package in your system.
Once you install this, your instance will get activated. Connect your Db once again.I am sure it will work.
In case, if this error comes again, you can follow these steps:
Hit Windows + R and type services.msc and hit OK
From the given lists, search for SqlServer (SQLEXPRESS) and click start the service. This will activate your instance once again and your database is now ready to connect to your application.
Hope this helps.
I worked with c#(started to work). At first I created model. And by this model I created MVC 5 controller with views, using Entity Framework. I thought that all correct (that necessary table will be created by this model, and I can worked with local database), but when I would like to run my application and go to this page http://localhost:49640/ControllerName I get this error:
Additional information: 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
I tried to find some solution, but I didn't. As I understood it can be some problems with connectionStrings in Web.config or some problems with connection to server, but how solve this problem?
My connection strings:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MusicApplication-20150620120938.mdf;Initial Catalog=aspnet-MusicApplication-20150620120938;Integrated Security=True"
providerName="System.Data.SqlClient" />
I download SqlLocalDb and installed it, this solve my problem. This link connection to local db failed 52 helped me.
I have used IIS before, but I've never used a database and I've never done a web app. I did the same steps for putting a site onto IIS and everything works EXCEPT for when I go to a page that has a DB connection on it. I've tried a lot and this is all I get.
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. See the Windows Application event log for error details.
Windows Application Event Log:
Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.
This was built in Visual Studio and I have a SQL Express DB.
I posted my connection strings, any help is greatly appreciated.
I have added this to my applicationHost.config:
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
And now I get:
An attempt to attach an auto-named database for file |MY DB1 FILE| failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB1.mdf;Initial Catalog=aspnet-ICCAA_VIZIER-20150223043129;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB2.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>
I was able to figure it out. I changed all my data connections to .\SqlExpress. Which led me to another error of:
Login failed for user ‘NT AUTHORITYNETWORK SERVICE‘
To fix this I followed this guys article to figure it out.
Login Failed For user NetworkService
I have created a login application using ASP.NET and SQL Server. It runs perfectly on my localhost but as soon as I uploaded it on GODADDY, I got the ERROR regarding the connection string.
I have also changed the connection string with the one provided by GODADDY but it did not work.
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).
Exception Details: System.Data.SqlClient.SqlException: 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)
I have made DLL and BLL namespaces to which i gave reference of my asp.net application.
I have used connection string in two files (1) in DLL/clsdll.cs file (2) in web.config file as follows
Connection String in clsdll.cs file :-
con = new SqlConnection("Data Source=XXXX;Integrated Security=False;User ID=ZZZZZ;Password=YYYYY;Initial Catalog=demo1;Connect Timeout=15;Encrypt=False;Packet Size=4096");
Connection String in WEB.CONFIG file :-
<connectionStrings>
<add name="SampleConnectionString"
connectionString="Data Source=XXXX;Integrated Security=SSIP;User ID=ZZZZZ;Password=YYYYY;Initial Catalog=demo1;Connect Timeout=15;Encrypt=False;Packet Size=4096"/>
</connectionStrings>
The connection string above is the one provided by GODADDY but it doesn't work.
Can anyone help me out with this please....
only this much info is required you can remove the rest and try once
data source=XXXX;user id=XXXX; password=XXXX; initial catalog=XXXX;
Well, in your web.config, you have both the "Integrated Security" (with a spelling typo - it should be Integrated Security=SSPI) as well as an explicit username/password.
Don't do that - either you use integrated security (unlikely, in a hosted environment), or then you use user ID=.../Password=... - but don't enable BOTH at the same time!
In your case, I would try
<connectionStrings>
<add name="SampleConnectionString"
connectionString="Data Source=XXXX;Initial Catalog=demo1;User ID=ZZZZZ;Password=YYYYY;"/>
</connectionStrings>
I have ASP.NET app with database which is updated by C# application, so database is placed on my local disc. .NET app can only read entries (changes are not allowed).
I can run my .NET app from local host (from Visual Studio or/and IIS) or other computer in network by ipaddress:port_number/page_name.aspx. Everything is working fine.
But now I would like to publish my app on somee. :) I made account and in the same project I added one simple page (just plain text) and that page can be accessed my other computers fron Internet by typing myusername.somee.com/that_simple_page_name.aspx
I found a lot of similar topics on the Internet forums so I made changes:
- TCP/IP enabled in SQL Server Configuration Manager
- exceptions ports 1433 and 1434 (UDP),
- SQL Server Browser enabled...
I made .zip of folder created during IIS publishing (c:\inetpub\wwwroot\My_App_name) and uploaded it to the some by File Manager Upload. But when I tried to access to the page with readings from database I got error
Server Error in '/' Application. 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) Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 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)
I believe that problem is with my connection string. My current connection string (web config file uploaded to the somee and on my Visual Studio 2013 Ultimate) is:
<connectionStrings>
<add name="_web_server_test.Properties.Settings.Base1ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Database Somee web\Base1.mdf";Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
Can you recognize what is the problem and how to change connection string?
Thanks.
You first have to create the database manually in your dashboard.After creating a database the page will show you the connection string you can use in your webconfig file.
make sure that you pick the right SQL version on the somee dropdown, the latest version is what worked best for me.