-1

Quite simply, what is the correct connection string to an mdf file database located in the App_Data directory of my asp.net website hosted on Godaddy? Naturally this works offline in my developer environment but causes problems when uploading to Godaddy. Does Godaddy support connecting to databases contained within the App_Data directory? I suspect my problem is the Data Source portion and selecting a SQL Server instance but I'm not sure.

I clear the "LocalSqlServer" connection before adding the actual connection string info first.

<connectionStrings>
    <remove name="LocalSqlServer"/>
    <clear/>

And here's what I've tried with varrying errors:

1.

<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;|DataDirectory|\DatabaseFileName.mdf&quot;;Initial Catalog=&quot;DatabaseFileName&quot;;Integrated Security=True" providerName="System.Data.SqlClient" />

Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

2.

<add name="LocalSqlServer" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=&quot;|DataDirectory|\DatabaseFileName.mdf&quot;;Initial Catalog=&quot;DatabaseFileName&quot;;Integrated Security=True" providerName="System.Data.SqlClient" />

Error: [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]

3.

<add name="LocalSqlServer" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=DatabaseFileName;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\DatabaseFileName.mdf" />

Error. Same as number 2 above.

Many many thanks for assistance on this!

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
lg1382
  • 71
  • 11
  • The error above indicate your connection string is incorrect. You must upload full .bak file, you cant only upload .mdf file on server as it wont work. Please check it again with them for more information. –  Jul 25 '16 at 04:56
  • I've played with this additionally and have gotten it to display this error: Invalid value for key 'attachdbfilename'. That leads me to believe it's connecting to the Database server, but not allowing me to attach the database. Are you familiar with Godaddy specifically? I'm starting to believe they don't allow you to connect to a database in App_Data. Could you provide a link describing the entire process with the .bak file you mentioned? Thanks! – lg1382 Jul 25 '16 at 05:42
  • .bak consist of 2 file, .mdf and .ldf file. You may need to check with your developer. I dont use godaddy as my hosting, so I dont know their process. But, in production server, you need to upload .bak file for restoration. It wont work with .mdf file –  Jul 25 '16 at 07:40
  • I am the developer. I have both the mdf and the ldf file uploaded to the App_Data folder and have tried all kinds of combinations to get it to work. The closest I've gotten is the attachdbfilename value error but my connection follows everything I've seen online. AttachDbFilename=|DataDirectory|\.mdf. GoDaddy support was useless on this question also. – lg1382 Jul 25 '16 at 20:59
  • You need to convert it to .bak. You cant restore .mdf and .ldf file to server. Please see http://stackoverflow.com/questions/4615521/how-to-convert-mdf-ldf-database-files-to-bak-file-db-restore-using-t-sql-or –  Jul 26 '16 at 02:25
  • I don't think we are on the same page. I do NOT want this database stored within their database server. I want to attach it to their sql server when it's needed at runtime, but ultimately store the database within my site's App_Data folder. To do that, my understanding is you need to use the "attachdbfilename" in the connection string... this works in a development environment. I'm trying to figure out if Godaddy allows that - because it doesn't seem to work when I set the "Data Source" (the database engine effectively) to sqlexpress, localdb, or the godaddy database sql server url. – lg1382 Jul 26 '16 at 18:08

1 Answers1

1

Not much response on this question, but from my calls with GoDaddy, I'm going to say the answer is No - they do not support databases stored in your local App_Data folder. From experimenting with this problem, I found that to do what I wanted to do, you need to specify two things in the connection string of your web.config file.

  1. DataSource: The sql server database engine. In development, this is commonly set to sqlexpress or localdb.
  2. AttachDbFilename: This is the reference to the mdf database file in App_Data.

I was able to set my DataSource to an instance of SQL Server on Godaddy, however, when using the AttachDbFilename attribute, I would get a server error saying there was a problem with my AttachDbFilename value.

GoDaddy support (at least the agents I spoke with) gave conflicting information. The first agent was obviously not confident in what they were talking about but said "it's possible" but claimed because of their statement of support he couldn't help me figure it out. The second agent was more knowledgeable and was actually messaging with (I presume) an actual database tech that basically stated it won't work.

In the end, I should have realized this was not possible sooner as it's their business model to sell you additional databases once you have used the two they include in the shared hosting plan. It would just be nice if they would say directly on their DB admin page in the Hosting Manager that attaching databases is not allowed... would have saved me time and aggravation.

If anyone has successfully attached to their App_Data mdf - post your connection string, otherwise I'm marking this as the answer as soon as SO will let me.

lg1382
  • 71
  • 11