I'm trying to upload the personal website starter kit to a web hosting site, and cannot get the connection string correct.
I want to use the personal.mdb in the App_Data folder within my site, which works fine locally, but once uploaded, I get all kinds of errors - depending on how I mess with the string. In no interation can I get the string to work when trying to use the <AttachDBFilename> entry.
When just adding the connection string provided by the hosting service to connect to their server, it opens, but obviously none of the website database functionality works.
I am assuming that I will be using the SQL engine on the server, and pointing it to my database file.
Here is the complete database connection string from the personal website starter kit:
<
add name="Personal" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Personal.mdf" providerName="System.Data.SqlClient" /><
remove name="LocalSqlServer"/><
add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf" />Here is the connection string as provided by my hosting service:
Data Source=whsql-xxxxxx.xxxx.mesa1.secureserver.net;Initial Catalog=DB_xxxxx;User ID=mxxxx;Password=abc123xxx;
Here is one of the errors I've gotten:
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 5: Sub Application_Start(ByVal sender As [Object], ByVal e As EventArgs)
Line 6: AddHandler SiteMap.SiteMapResolve, AddressOf Me.AppendQueryString
Line 7: If (Roles.RoleExists("Administrators") = False) Then
Line 8: Roles.CreateRole("Administrators")
Line 9: End If
Thanks for the help!
Matt

SQL Connection String Assistance
Takado
Here is my current connection string, with theedit from the last post:
<
connectionStrings><
add name="Personal" connectionString="Data Source=whsql-xxxxxxxx.mesa1.secureserver.net;Initial Catalog=DB_xxxxx;User ID=mattk;Password=xxxxxx;AttachDBFilename=|DataDirectory|\personal.mdf" providerName="System.Data.SqlClient"/><
remove name="LocalSqlServer"/><
add name="LocalSqlServer" connectionString="Data Source=whsql-xxxxxxx.mesa1.secureserver.net;Initial Catalog=DB_xxxxx;User ID=mattk;Password=xxxxxx;AttachDBFilename=|DataDirectory|\aspnetdb.mdf" providerName="System.Data.SqlClient"/></
connectionStrings>Unfortunately it did not have any effect on the problem.
Thanks
Matt
Dpowes
Thanks for that reply. I understand now the limitations of my hosting service and what I need to do to use SQL and the personal web site.
Thanks for the assistance, I do appreciate it!!!
Matt
Victor Delta
that is correct, both .mdf's are in the correct location on the hosting site.
Thanks,
Matt
Sire
Thanks for this post - its the first sensible one I've seen on this topic (which seems to be an incredibly common problem).
I have the same problem in that my web server & SQL server (at a hosting company) are different. My workaround has been to create the db/tables in SQL 2005 using the SQL script for this db that is supplied with the project and then change my web.config connection to reflect this:
<connectionStrings>
<clear/>
<add name="Personal" connectionString="Server=SQLB12.webcontrolcenter.com;Database=markgalliers;User ID=markgalliers;Password=kat5112; " providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=.\personal\App_Data\aspnetdb.mdf" />
</connectionStrings>
However, my problem now is that I don't have the aspnetdb.mdf db or SQL script for it, besides which I'm not sure when this can also be transferred to SQL 2005
Do you have any idea whether this is possible, or even better whether you have a SQL script for this db
Thanks in advance
Mark
ReneX
You may be missing the backslash as a directory separator - did you try
|DataDirectory|\Personal.mdf
as suggested by http://msdn2.microsoft.com/en-us/library/ms254499.aspx
Robert_L
Matt,
This was a bit surprising at first but I finally understand what's happening. When you use AttachDbFileName in conjunction with |DataDirectory| and the Data Source keyword, we enforce that the client machine name is the same as the Data Source machine name. What I'm assuming is happening on your hosters machine is that the Data Source name, whsql-XXXXXXX.mesa1.secureserver.net, is in fact a different name than the ASP.NET Web Server that your pages are being hosted on. We require that the SQL Server is installed on the local box in order to take advantage of |DataDirectory| in your connection string. So in order to use it you'll need to have your hoster provide you access to a Sql Server install (SqlExpress would work) on the same machine. The change Data Source to be equal to the local machine and it will start working.
Does this make sense Can you verify this works for you
Thanks
Carl Perry
ADO.NET Program Manager
Jim Hunt
I have a like problem. Can you help me
An attempt to attach an auto-named database for file e:\wwwdata\LocalUser\lubos.9d5aae\www\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
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: An attempt to attach an auto-named database for file e:\wwwdata\LocalUser\lubos.9d5aae\www\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Source Error:
Line 5: Sub Application_Start(ByVal sender As [Object], ByVal e As EventArgs) Line 6: AddHandler SiteMap.SiteMapResolve, AddressOf Me.AppendQueryString Line 7: If (Roles.RoleExists("Administrators") = False) Then Line 8: Roles.CreateRole("Administrators") Line 9: End IfSource File: e:\wwwdata\LocalUser\lubos.9d5aae\www\global.asax Line: 7
Stack Trace:
<
connectionStrings><
add name="Personal" connectionString="Data Source=.\SQLexpress;Integrated Security=True;User Instance=True;Database=Lubos25489;AttachDBFilename=|DataDirectory|Personal.mdf" providerName="System.Data.SqlClient"/><
remove name="LocalSqlServer"/><
add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf"/></
connectionStrings>Where I wrong. Thank you!
Roger Swetnam
Hello,
I have the same problem. What is the way around if the hosting provider doesn't allow SQLExpress or SQL Server Install
Thanks
MKashay
Is the aspnetdb.mdf file in the Data directory on the target machine
I am moving this to the ".NET Framework Data Access and Storage", which has a better chance answering the question.