I have an asp.net web app running on IIS, and everything is fine, until I try to access the database I get this error:
I have read the 2 parts of the Using LocalDB with Full IIS: 1 Part | 2 Part
I followed the instructions and still get the error, is there a way to check that I have followed the steps correctly?
Is there anything else I can check for that may be causing this error?
Note: I tryed this with asp.net and asp.net core applications, the core one doesn't give any description at all so I am testing this with asp.net. The database that I am using is the one that visual studio provides. If you would like me to provide any further information ill be happy to, I have been stuck with this issue for a while now and can't seem to resolve it.
Turns it's not too complicated, but my inexperience with both IIS and Databases made it confusing. Hopefully this can help someone in the future. There might be some minor steps/tweaks I missed out but that's because the whole solution took a while to setup.
Make sure you have SQL Server actually installed. You can download the 2008 version which I used here. Can be a pain to setup and I actually messed up when installing, here is the vid I watched (I didn't install: Database Engine Services).
Next you want to make sure the IIS identity (IIS APPPOOL\ASP.NET v4.0 in my case) has permission to connect to the Database server. Check the answer here.
Once it has connected to the database server, it need's to be able to connect to a database on the server (I didn't know that a database and a database server are 2 different things). You need to do something simular to Step 2, in SSMS expand the databases folder, and select the database you which to grant access too, there is a security folder in there as well and you want to add the Identity to that folder.
Other useful points:
If your sql configuration manager isn't opening please tell it to, thank you gofr1. This is a very useful tool for checking up on your database connection (as it turns out)
Make sure you setup your connectionString to point to the sql server. Make sure it doesn't connect to the mdf file with AttachDbFilename=|DataDirectory|\your_database_name_here.mdf located in the connectionString.
For asp.net Core read the documentation it is god, as the errors are non-existent once the app is deployed on IIS it will help in dark times. Always check publishOptions.
To further help you understand how the whole process works, thank you to gofr1
read here. Didn't solve the issue but worth a read.
Might include more stuff in here later if I remember I missed anything out.
Related
I am having this problem for more than a day already so I decided to ask for help.
Picture of the Error in IIS deployment
I can successfully test my ASP.NET project on the IIS Express from Visual Studio, the connection string works perfectly. Also, when running my program.exe located in the IIS deployment folder it also connects perfectly to the localdb.
Unfortunately, when using the live IP address of my project the error appears, so my guess is that it is connecting to the DB but it is not being able to retrieve or push data to it for some reason.
I tried to use different methods of DB connection, localdb, shared localdb and SQL Express.
None worked.
My connection string is the following:
Server=(localdb)\\MSSQLLocalDB;Database=PaymentConnect;Trusted_Connection=True;
I have tried to add the EnableRetryOnFailure to my code, unfortunately the error remains, after the allowed tries it fails again.
I literally have no experience deploying projects to IIS, and neither have experience on ASP.NET. If anyone can help me it would be great! Thanks!
If I forgot to add something please let me know so I can update the question
The error unfortunately is generic, it only says that something went wrong and possibly is a transient failure. But my issue is actually solved, for those experiencing the same issue as I am here is how to solve it.
Instead of using localdb you should download and set up SQL Express, it is like a local server but shared with all users on the PC, you will need that because when IIS tries to open your localdb it will actually do so as its own user, and so the localdb is different. Remember to change your connection string on the app, it should look something like this: "DefaultConnection": "Server=.\\SQLEXPRESS;Database=PaymentConnect;Trusted_Connection=True;"
After doing that you need to create a security user on the DB like so:
IIS APPPOOL\nameOfMyAppPool
where nameOfMyAppPool is the name of the Application pool your website is using.
Now after that what I did, which I am not sure is needed, is that I gave this security user sysadmin Server Roles, you will see this when creating this user, also on user mapping you select your DB and give it db_datareader db_datawriter and db_owner for it.
After doing that go to your DB and click to see its properties, you will need to go to permissions and give this new user you just created permissions to:
select delete insert update connect replication execute references control
Once more I would like to remind that this is how I resolved the issue, I am not sure which of these are really necessary or not.
And that should do the trick.
I am developing razor pages web app that uses Microsoft entity framework that connects to SQL server. It all works in when running straight from visual studio (IIS Express), but when I tried to deploy it on IIS, SQL connection no longer worked.
connection strings i have tried:
Server=localhost;Database=zzzz;Trusted_Connection=True;
Server=DESKTOP-R7J0NGU;Database=zzzz;User Id=yyyy;Password=xxxx;
The application deployed on IIS does not give any information what is causing a problem, is it server, is it database, or authentication problem.
Any help is appreciated
Sorry to bother anyone.
the connection string has worked:
Server=DESKTOP-R7J0NGU;Database=zzzz;User Id=yyyy;Password=xxxx;
the problem was that the user "yyyy" did not have correct permissions to see and modify database tables. It did cost long time figuring out because my application in release build did not give any information as to why it might have failed.
I have one problem that's causing more problems.
Let me explain what's going on:
For the past week, wanted to learn ASP.NET MVC and develop an app.
To get my machine ready, installed:
Visual Studio Enterprise 2017 32/64-bit (Multilanguage)
SQL Server 2016 Enterprise With Service Pack 1 64-bit (English)
So, after that, I thought to be good to go.
This is the app I'm using to do the learning: APP.
Then, once I open in Visual Studio, this is what happens first:
Didn't really understand this message. but my thought remained: how can I open using SQL Server 2016?
This "problem" quickly vanished with:
Ok, let's still try to do a build and see what goes on:
Cool, I'm able to see the app.
Well, now that I'm in a "lucky day", let's test to register:
This last error has to do with the protocols selected for the server.
It has to do with MS SQL Server configuration. Which means, I may need to install additional ODBC drivers for MS SQL.
How can I fix this and be able to register?
Note: If there's any info you might find important in order to understand how to help me with this problem, let me know. This because I'm a noob in the field, just getting started.
Here is the course I've been following.
You need to create a database in your SQL Server 2016 and then update your connection string to use that database.
Your connection string should look like
Server={server name},1433;Database=tiagoleft.music_shop.dbo;User ID={user id};Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
Note: while installing, if you configured only windows authentication, then you have to update the connection string to use windows authentication. For that to work, replace the user id and password from the above string with
Integrated Security=True
So I am assigned a projet on a company where I am to fix up and add some features as a side-project for the company. I have a almost complete website (13 000 lines of code or so) in C# and JavaScript. I have a local copy of the website and the database and I want to just toy around with my local database so I can try things out and not ruin the entire website/database.
I am relatively new to JavaScript and I kind of understand C# by now. I think I have found where I am supposed to change the database connection but not sure how I am supposed to do it, or what to change it to. The local database is on my desktop, next to the local copy of the project if that helps. This is where I figured I should change:
<connectionStrings>
<!--add name="MySqlConnection" connectionString="DATA SOURCE=11.11.111.11;
DATABASE=websitename;USER ID=websitename;PASSWORD=xxxxxx;PORT=1234"/-->
<add name="MySqlConnection" connectionString="DATA SOURCE=localhost;
DATABASE=websitename;USER ID=username;PASSWORD=xxxxxxx;PORT=1234"/>
</connectionStrings>
Also: shouldn't I be able to test this locally when I have no internet connection? Because right now it seems that I can't. Any tips are good tips. The weird thing is that the code wasn't runnable because of 2 errors (2 functions took 37 and 38 arguments instead of 38 and 39) and after I fixed that I could run the program in Visual Studio through Google Chrome. This should imply that the local code is running - right?
Well...if I change some hard-coded text on the website or add something in the menu it doesn't change when I run the program - this would imply that it's the version on the server running when I do it. But then why would it not run with the errors (that somehow doesn't bother the website for some reason)
I am very confused right now...sorry for a long post. Any help would be great.
lots of vague questions. Strip it down to essentials.
When you build the project in visual studio you can choose where to deploy it. It sounds like in IIS the folder is set to something other than your build folder (which is fine) but that means you have to redeploy when you build to see the changes.
if local host is requiring an internet connection make sure your hosts file in windows is configured properly.
you found the right area (maybe) for hte connection string - depends on how its coded up in the app though. It doesn't look like you are using a sql server database though because you have no provider info in the string. So you need to break this into several questions because there could be a chunk of code for each part.
If your live and local database stored information is not parallel then For testing purpose generate a database script from live database with schema and data.Then deploy it to local IIS.There is no need for internet for localhost database.
How can I make a program use a SQL Server database, and have that program work on whatever computer it's installed on.
If you've been following my string of questions today, you'd know that I'm making an open source and free Help Desk suite for small and medium businesses.
The client application.
The client application is a Windows Forms app. On installation and first launch on every client machine, it'll ask for the address of the main Help Desk server.
The server.
Here I plan to handle all incoming help requests, show them to the IT guys, and provide WCF services for the Client application to consume.
My dilemma lies in that, I know how to make the program run on my local machine; but I'm really stumped on how to make this work for everyone who wants to download and install the server bit on their Windows Server.
Would I have to make an SQL Script and have it run on the MS SQL server when a user wants to install the 'server' application?
Many thanks to all for your valuable time and effort to teach me. It's really really appreciated. :)
Edit:
To clarify, each business will have their server completely separate from me. I will have no access whatsoever to them nor will they be in any way connected to me. (I don't know why I should clarify this :P )
So, assuming the have ABSOLUTELY NO DATABASE SERVER installed; what can I do?
Ok, part of the answer, dealing with the SQL Server Database (and frankly SQL Server Express will take you a long way - 4Gb of data) and the server install elements.
Firstly make installation of the SQL an SEP, make it a pre-requisite possibly tweak your installers to test (challenging) but substantially point them at the links to SQL Server express and let them get on with it).
Secondly separate installers, as suggested, for your client and your server elements.
Finally, how to build the database - I'd suggest using code to create and maintain (update) the schema i.e. once you have a connection to a server you can run code that calls DDL that does what is necessary (something like suggested here: How to create "embedded" SQL 2008 database file if it doesn't exist?)
A question - are you intending all communications from the clients to go through you WCF service?
Your install application should:
Obtain a SQL Server name, a username (with apprpriate rights to create a database) and password.
Either run SQL scripts using the locally installed command line tool or from code using SMO (for instance), against the user supplied server with the supplied credentials.
BTW, Before you expend effort writing an open-source help desk, have you checked what is already available? Also, Open Source Helpdesk
It is not so straightforward to deploy a client/server solution with an automatic installation.
You probably would then be better off to deploy your server installation together with a database engine and a skeleton database already setup according to your wishes. This is to avoid tampering too much with the existing server - who knows whats on it.
Also you say you want to install WCF services, well this would probably mean installing them on a customer server, in theory this shouldn't be a problem however in reality it could be, depending on what is previously on the server.
Do you want a single SQL Server instance running on your machine, or one on each of your customers' servers? If it's the latter, you'll want to install a SQL Server instance - anything from the (free, but limited and not open-source) SQL Server Express to a more expensive SKU - on each server. You can include this step in your server installation package; MSI installs make it very easy to bundle a MSSQL install.
Then you'll need to drop a schema, and maybe data, on the instance. You could do this as a step in your installer, or as part of your application setup process. It possible that a SQL Server instance, or more than one, might already be installed on the server, and your post-install step should allow the user to specify which instance on which to install your pieces.
Then, include a database configuration piece in your client application. Ask the user - or take from a configuration file at client install time, to allow for unattended or unprompted client installs - server connection details, like server name and authentication information.
A word on authentication - since you appear to be building Windows-based tools, use Windows integrated (domain-managed) authentication if at all possible. Don't get in the business of storing logins, but instead rely on the existing domain to manage logins. A good strategy is to use active directory groups to manage access. Grant access to a particular group in SQL Server, and defer group membership to Active Directory itself. If you can't gain the access necessary to do this, then grant permissions to AD user accounts themselves. Avoid creating SQL Server logins, the use of which open the door to some possible security problems.
I understand what you are trying to do. If I were you, I'd do the following:
Provide 2 downloads - 1 for client and 1 for server.
Forget about MS SQL Server and perhaps go with MySQL, since it really is open source. You could probably get away with using MS SQL Server Express Edition, but if your data set gets gigantic large (which is common with help desk databases), you'd be stuck.
As other people pointed out, on very first run (or at setup time), I'd have the client app locate the server.