问题
I know its a classic problem, but I am too novice to even comprehend the basics (sorry). I have this ASP.NET "Website" with databases (SQL Server 2008), which I am trying to deploy on a Remote Host Server (HostGator) using WebSite Copy tool of VS 2010.
In VS 2010, I could grab the Connection string directly through the "property" of the database, which turned out to be:
Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\myName\Documents\Visual Studio 2010\WebSites\Experiment\App_Data\data.mdf";Integrated Security=True;User Instance=True
Now, I know that a website called http://connectionstrings.com/ exists, but its too overwhelming for me at first glance.
My current connection string:
Data Source=domainName.com\SQLEXPRESS;AttachDbFilename=C:\inetpub\vhosts\domainName\httpdocs\Experiment\App_Data\data.mdf;Integrated Security=True;User Instance=True
I am pretty sure, that this is wrong as its giving me the classic error of:
A network-related or instance-specific error occurred while establishing a connection to SQL Server..
But I don't know how to fix it. Where to start looking, how to initiate, how to get the parameters required to build the connection string. How to find the path of the AttachDbFilename
? Can you please help?
I believe, that connection string is the only parameter which needs to be modified. If there's something else, then please suggest? Also, I keep coming across the usage of SQL Management Studio to make things work, I don't have that, so is it hard to accomplish this without it?
Please help, thanks.
回答1:
You can't specify a directory relative to your own machine. Change AttachDbFilename to
AttachDbFilename=|DataDirectory|data.mdf
The specifics for Data Source
should be given to you from your hosting company, as well the security model (probably you need to use a specific user)
You can download SqlServer Management Studio Express from this link
回答2:
Man,
What do you think about HttpServerUtility.MapPath Method. It returns the physical file path that corresponds to the specified virtual path on the Web server.
[]'s
回答3:
When you get your hosting. They will provide the connection string for you. like this
<add name="ConnectionStringName"
connectionString="Data Source=localhost;Database=YourDatabaseName;Uid=YourUserNameForDatabase;password=yourpassword;"
providerName="System.Data.SqlClient" />
Let me know, if you need more help
来源:https://stackoverflow.com/questions/12057431/connection-string-for-remote-sql-server-2008-without-sql-management-studio