Connection string problems on shared hosting with sql server 2005 express
I have a problem connecting to my db on a shared hosting. My host provider says they deployed SQL 2005 express on their database and I prepared my connection string as follows to take advantage of sql express.
<add name="PMIS_DBConnectionString" connectionString="Server=localho开发者_如何学Gost;AttachDBFilename=|DataDirectory|PMIS_DB.mdf;Database=PMIS_DB;Trusted_Connection=Yes" />
</connectionStrings>
<system.web>\
The data source name I used originally was ./SQLExpress, but my host provider asked that I change it to local host, although with the former it didn't connect, but still with the change as indicated above the error still comes up on access to my default page. The error is as follows: Server Error in '/' Application. Invalid value for key 'attachdbfilename'.
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.ArgumentException: Invalid value for key 'attachdbfilename'.
Source Error:
Line 120: Public Function GetID(ByVal sLgaName As String) As Integer Line 121: Dim q As String = "Select PLID " & "From LGA " & "Where LGAName = " & "'" & sLgaName & "'" Line 122: Dim cn As New SqlConnection(Me.ConnectionString) Line 123: Dim cmd As New SqlCommand(q, cn) Line 124:
I've read up a lot on the web and Googled my fingers numb on this. I have a deadline to deliver this project and having successfully built the app it's frustrating for this to happen. Please help me.
Does you hosting provider support attachable databases (ie. AttachDBFileName?). Most hosting providers don't allow this. The error message seems to indicate pretty strongly that that's the case. Attacheable databases are an Express only feature, and hosting providers offer one database per account on a shared instance, I didn't hear of providers offering Express instances per account.
So you are going to connect to your designated database on the shared instance, created for you by your provider, not to the MDF file you copied. In order to deploy your schema now you need to run a deployment script with the various CREATE TABLE, CREATE VIEW, CREATE PROCEDURE statements that build your application schema. If you do not have a deployment script, then learn your lesson and create one. Developing applications from the VS Server Explorer is great in demos done at shows, but not the trenches doing real deployments.
精彩评论