虚拟主机上的 MVC 3 ASPNETDB.MDF SqlExpress 数据库连接字符串
我认为这更像是 MVC 3 的连接字符串问题,所以提前抱歉。
我在 MVC 3 中创建了一个网站,其中使用了注册新用户时创建的默认数据库。它在本地运行良好,但在我的网络托管上却不起作用,我收到以下错误:
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:SQL 网络接口,错误:26 - 定位指定的服务器/实例时出错)
默认连接字符串为:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
我应该指定带有服务器的显式 IP 地址的连接字符串还是保留 .\SQLEXPRESS 命令?如果我需要指定用户名和密码,那么我应该使用什么?我以前从未使用过本地 SQLExpress 数据库,所以我一无所知(我确信这是显而易见的)。
I think this is more of a connection string issue that MVC 3, so sorry in advance.
I've created a website in MVC 3 with the default database that is created when you register a new user. It works fine local but not on my web hosting where I receive the following 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)
The default connection strings are:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
Should I specify a connection string with an explicit IP address of the server or retain the .\SQLEXPRESS command? If I need to specify a username and password then what should I use? I've never used a local SQLExpress database before so I'm clueless (which I'm sure is apparent).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您无法使用 SQL Express,那么您可以考虑使用嵌入式 SQL 引擎:
SQL Compact Edition 或 SQLLite
我从未使用过 SQL CE,但 SQLLite 只是一个 DLL。
显然,您不具备成熟的数据库引擎的所有功能,但它们仍然非常强大。
If you cannot use SQL Express, then you could consider an embedded SQL Engine:
SQL Compact Edition or SQLLite
I've never used SQL CE, but SQLLite is just a single DLL.
Obviously you don't have all the features of a fully fledged database engine, but they are still pretty powerful.
一般来说,您需要使用具有特定 IP 地址、用户名、密码等的连接字符串。
您由谁托管?通常,.net 主机提供商会为您提供用于连接数据库的连接字符串。您可以复制并粘贴到您的 web.config 中。此外,当他们为您创建数据库时,他们通常会指定用户名、密码和数据库名称,因此您必须更改所有这些。
这是 Visual Studio 具有带有 xml 转换的 Web.config.debug 和 Web.config.Release。这样,当您发布到站点时,连接字符串会自动从本地连接字符串更改为生产环境中使用的连接字符串。
Generally you will need use a connection string with a specific IP Address, Username, Password, etc.
Who are you hosting with? Generally a .net host provider will give you the connection string to use to connect to your database. You can copy and paste in to you web.config. Also, when they create the database for you, they generally specify the username, password, and database name so you will have to change all of that.
This is visual studio has Web.config.debug and Web.config.Release with the xml transformations. This way when you publish to the site, the connection string is automatically changed from your local connection string to the connection string used in your production environment.
您可能需要关注这篇文章?
http://www.asp.net/mvc/tutorials /authentiating-users-with-forms-authentication-cs
默认“.net”将应用程序服务安装到"AttachDBFilename=|DataDirectory|aspnetdb.mdf"
然后您创建自己的数据库,现在您使用两个数据库来存储可能只存在一个数据库中的数据。
如果您阅读了上面的文章,它会向您展示如何将所有内容组合到一个数据库中。
当您部署到托管服务器时(它对您可以使用的数据库数量有限制,甚至不运行 sqlexpress),都不会附加数据库。因此,您需要为您的 web.config 文件(通常是调试和发布)创建一个“转换文件”,该文件基本上是另一个 web.config,但仅包含配置行,因为当站点部署到托管时您需要更改服务器。
因此,您的托管提供商将为您提供服务器上连接字符串所需的详细信息。然后将其放入“web.config.release”文件中,当您编译并发布站点的“release”版本时,您将获得一个包含正确连接字符串数据的 web.config 文件。
You probably need to follow this article?
http://www.asp.net/mvc/tutorials/authenticating-users-with-forms-authentication-cs
Deafault ".net" installs Application Services to "AttachDBFilename=|DataDirectory|aspnetdb.mdf"
Then you create your own DB and now you're using two DB's to store data that could just be in one.
If you read the above article it shows you how to combine everything into one DB.
When you deploy to the hosting server (and it has a limit on how many DB's you can use or isn't even running sqlexpress) neither DB attach. So you need to make a "transform file" for your web.config file (usually Debug and Release) which is basically another web.config but only with the lines of config in that you need to change when the site is deployed to the hosting server.
So your hosting provider will give you the details needed for the connection string on the server. You then put that in the "web.config.release" file and when you compile and publish the "release" version of your site you will get a web.config file that has the correct connection string data in.