Search code examples
asp.netsql-serverlocalhostaspnetdb

How to use ASPNETDB on shared hosting?


On my asp.net site I use local DB, connection string is

Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MyDataBase.mdf;Integrated Security=True;Connect Timeout=30

So, MyDataBase.mdf is in APP_DATA folder.

I need to use standard asp.net membership provider, for that I run utility C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regsql.exe and it created me new DB ASPNETDB.MDF (and log aspnetdb_log.ldf) in APP_DATA folder, I filled it with users and roles via "ASP.NET Configuration"

I uploaded it to my shared hosting and site works great, inclede getting data from MyDataBase.mdf database, but once I want login user which is in ASPNETDB.MDF, site throws an 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)

How to resolve that problem?

Thank you!


Solution

  • I am not sure what you mean when you said "... site works great, ..." (your site, their site).

    Most shared hosting sites that I have run sites on do not allow SQL Server Express databases to be run due to its resourse management.

    What you need to do is use the sites SQL Server database. Through their admin console you should see a way to to create a database instance. They will/should give you the connection string that your program will use to connect to the database. With this connection string, you may or may not be able to connect to it from home (some web hosts allow this others do not).

    If you can connect through home using Sql Server Management Studio, then you are in good shape. You can use the aspnet_regsql.exe and point it to the hosted database (using the connection string option) and have it generate all the tables, views, roles, etc.

    If you cannot connect directly to the database from home, have SQL Management Studio generate a script (Right click database -> Tasks -> Generate Scripts) and script the entire database. If you want the data to go as well, make sure you do the option to script data and scheme (not on by default). Then with this sql script (in a .sql file) you can upload it to the host and have them run the script through the admin console.