0

I am using Microsoft Visual Studio 2013 Ultimate.

I have one C# application connected with WSN to collect and save all sensor readings in database. It is working fine and stable.

Later I decided to add ASP.NET application (developed in the same software) so other computers in LAN can access my page and check measurements. I have one web form with few labels and buttons to ensure move forward and backward through the database table. It is working fine when I start it from Visual Studio but when I am trying to access from IIS it does not work.

I have this error (main part of the text):

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.

I have installed IIS and I can access "localhost" from my browser (IIS image appears). I published site with "Publish" option from Visual Studio.

I saw a few very similar questions on this forum but I did not find answer. Can you recognize what can be the problem?

Regards.

5
  • The account that your website's app pool is running under must be given access to the SQL Server. You could confirm this by changing the app pool account to be your account, as you say that it works when you run from VS. PS. Don't leave the website running under your account, as it's not good practice. Commented Oct 2, 2014 at 9:04
  • Please, can you be more specific what I should change in IIS. Commented Oct 2, 2014 at 9:22
  • I have now full connection with other devices in network but when I tried to open my C# application to connect with sensors I received this message: Cannot open database "C:\USERS\USERNAME\DOCUMENTS\VISUAL STUDIO 2013\PROJECTS\PROJECT_NAME\DATABASE_NAME.MDF" requested by the login. The login failed. Login failed for user "USERNAME". I do not have any password on my Windows account and I did not add any password to the database. Can you recognize what can be the problem? Commented Oct 3, 2014 at 6:39
  • The problem is that I can not access in the same time to the database from C# application and web application deployed on the server. For example, if I start C# app before web it is OK and I can use it to collect new data but if I try to access in the same time from web I have error in browser: Cannot open database "C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2013\PROJECTS\HOME SENSOR DATABASE\HOME SENSOR DATABASE\HOME SENSOR.MDF" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'. Commented Oct 3, 2014 at 7:23
  • 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: Cannot open database "C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2013\PROJECTS\HOME SENSOR DATABASE\HOME SENSOR DATABASE\HOME SENSOR.MDF" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'. Commented Oct 3, 2014 at 7:26

6 Answers 6

1

I think DeanOC's answer will apply if you are using your windows login to connect to sql server (in connection string you'll have Integrated Security=true) in which case:

  1. In IIS select you web application on the righ side click Advanced Settings a dialogue box will pop up in it you can see which application pool your website is using
  2. Close dialog go to Application Pools, right click the application pool you want and go advanced settings
    1. Change the Identity of the application pool, under Process Model, to your current windows login.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I am able now to connect through IIS but when I tried to access the same address from other computer (or mobile phone) in network (all connected on the same wi-fi) I got error message, and I could no access to the page.
0

The message implies that either sql server instance you are pointing to is not running or that you are pointing to the wrong sql server instance. If you are able to run the application from visual studio then sql server should be running and that would imply that your connection string is wrong.

During publish, msbuild will run config transforms i.e. if build profile is set to release it will change the connection strings in web.config to those in web.release.config. Check your connection strings in the IIS website and also check you password is correct

1 Comment

Yes, I selected "release" as build profile and I saw warning that database is not supported. But when I changed to "debug", it was the same so I kept "release". In web (XML Configuration file) I can see that there is good name for connection string in field <connectionStrings> </connectionStrings> with good path but I do not know if there some parameters are changed. During database creation I did not add any password for authentication.
0

You could enable TCP/IP in SQL Server Configuration.

Microsoft SQL Server xxx -> Configuration Tools -> SQL Server Configuration Manager -> Select TCP/IP. Right click and select enable

Therefore, you can connect successfully from your local computer but it fails when you access from IIS of other server.

4 Comments

How to enable that in Visual Studio 2013?
No, with SQL Server Configuration Manager where you've installed the SQL Server
I made SQL database in Visual Studio.
But you have installed a SQL Server Express in your computer, together with the Visual Studio
0

I think you are trying to access the web page from another computer in the network and not sql server in which case you have to add a binding to your site. By default the site is only bound to localhost port 80 meaning it will only be accessible from within the same machine. You'll need a url with dns entries or a static ip address to use to connect to your machine. Check out IIS bindings:

  1. http://blogs.technet.com/b/chrad/archive/2010/01/24/understanding-iis-bindings-websites-virtual-directories-and-lastly-application-pools.aspx
  2. http://technet.microsoft.com/en-us/library/cc731692(v=ws.10).aspx

1 Comment

I do not have static IP address because I am connecting on university's wi-fi. We have proxy which enables only port 80, but our administrator told me that it should be possible to have this connection because we are local network.
0

because you used attach Mode in this way when one of them is connected to your database other one cannot use it like open file. and only the one who is in the same sever could access to your database. to solve this problem you have to add your database to your SOL server manager after that you could access to it from many devices use this connection string

Data Source='server IP';Initial Catalog='database name';Persist Security Info=True;User ID='your user name';password='your password'

please follow this video enter link description here

Comments

0

Trick worked for me:-

  1. Go to the Base Directory of your project, then open .vs/{YourPorjectName}/Config, where you can see applicationhost.config file.

  2. Open the file, try to find the section

    < binding protocol="http" bindingInformation="*:50745:localhost" />

  3. Replace localhost with *.

  4. Close the Visual studio, run it as an administrator.

  5. In the last step you just have to go to Window defender firewall, then add a new inbound rule, where you will have to allow port on which your project is running.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.