Please some help on how to debug this!
On my development machine I can succesfully host a local WCF service that uses a SQLIte database for its storage. I simply xcopied the wcf service dll's, the database file and the System.Data.SqLite.dll to the win 2008 server. The server hosts the the WCF service in IIS7.This worked without a hitch before I tried to change to database based storage, so the WCF.IIS7 part is not the issue. While I am crudely testing whether the service is running by surfing to the service's .svc file in internet explorer I am greeted with theSQLiteException (0x80004005): unable to open database
message.The cause for this is that the location for the database file seems to be hard-coded: when I place the file in the exact same file location on the server as on the development machine the service starts without error.
The point is that I used the Add DataSource wizard to generate the code to access the database and specified that I wanted the Connection string to be stored as a setting in order to be able to place the databas开发者_运维知识库e file in a different directory later. I edited the web.config file to point to the database file's new location on the server, but it seems that this setting is not being read. Other settings in it pertaining to the WCF service are read correctly.Where have I gone wrong? The web.config follows below.
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<connectionStrings>
<add name="PrivateMessenger.Properties.Settings.PMDbConnectionString"
connectionString="data source=G:\PrivateMessengerServers\PMdevelopment\Data\PMDb.s3db"
providerName="System.Data.SQLite" />
</connectionStrings>
<appSettings>
<add key="PersistenceDirectory" value="G:\PrivatemessengerServers\PMdevelopment\Data" />
</appSettings>
<system.serviceModel>
...WCF stuff, is read correctly
</system.serviceModel>
</configuration>
Actually the web service does read the connectionstring from the web.config file. It turned out I copied the wrong xml element from the app.config file on the development computer. After I changed the xml to:
<connectionStrings>
<add name="MyDataSetLib.Properties.Settings.PMDbConnectionString"
connectionString="data source=G:\Data\PMDb.s3db"
providerName="System.Data.SQLite" />
</connectionStrings>
I was fine. So, if the connectionstring seems not to be read from web.config make doubly sure not to have made a typo, because it is the correct way to store alternative connection strings for stronly typed datasets.
Mind: the xml above works for strongly typed datasets within C# class libraries. For VB.Net change MyDatasetLib.Properties.Settings
to MyDatasetLib.My.MySettings
精彩评论