开发者

Database Deployment issues

开发者 https://www.devze.com 2023-04-08 15:52 出处:网络
I\'m having a hard time deploying my website. I got through some errors and they got resolved and I successfully published my website but when I try to open any page it gives me 404 or 500 Error

I'm having a hard time deploying my website. I got through some errors and they got resolved and I successfully published my website but when I try to open any page it gives me 404 or 500 Error

My host provider told me t开发者_如何学Pythonhat if this page is using a database and it's not deployed then this is might be the problem so I tried to deploy my database and I get the connectionString error.

The problem is that I'm not storing my connectionString in the web.config It's stored in a property in my base DAL class and it's used by all the DAL classes so I updated it but I get the same error

I dont know what's wrong, should I include the connectionString in the web.config ?

N.B When I build the package and I try to set the active mode to 'release' it returns the setting to 'debug'!


"should I include the connectionString in the web.config ?"

Yes, your connection string should be defined in the <connectionStrings> section of the web.config for precisely this reason - so that you can easily change the setting to point to a different database environment when deploying your application to a different environment, without needing to recompile your code.


IIS recognizes your connection strings in the config file. I've seen it exposing them through the IIS management console when viewing a certain application. I had a similar problem once and it turned out it was an authentication issue. Applications on IIS run in a certain pool and under a certain user. If you specified to use windows authentication (integrated security) in your connection string then this user must have rights to access the database. If the user that runs the application doesn't have the necessary rights to connect to the database you should specify the username and password explicitly in the connection string.

In any case you can turn on includeExceptionDetailInFaults in your web.config and get a little bit more information on why your service is failing like so (msdn):

<serviceBehaviors>
  <behavior>
    <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
</serviceBehaviors>


Assuming that your DAL is a class library, I would store the connection string in app.config. That way, you can easily change the connection string without having to put the connection string in every web application that uses the library.


"The problem is that I'm not storing my connectionString in the web.config It's stored in a property in my base DAL class and it's used by all the DAL classes so I updated it but I get the same error"

Yes, hard coding connection strings is a major problem. To answer your next question "should I include the connectionString in the web.config?", the answer is YES.

As for proper deployment of a database, you can look at this blog entry I created in 2008.


I'm sorry but all the answers advised me that I need to place the 'ConnectionString' in 'Web.config' but actually the whole problem was solved when I added my application to a virtual directory and I didn't need to change my DAL layer or add anything to the web.config

Of course I learned from your answers and I appreciate it but no I don't need to add anything in my web.config If I decided to have this design pattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消