简体   繁体   English

尝试使用可能的错误连接字符串将ASP.NET MVC连接到SQL Server 2008 R2

[英]Trying to connect ASP.NET MVC to SQL Server 2008 R2 with possible wrong connection string

Running SQL Server 2008 R2 and ASP.NET MVC 2 web application on the Virtual Server of big german hosting-provider. 在大型德国托管服务提供商的虚拟服务器上运行SQL Server 2008 R2和ASP.NET MVC 2 Web应用程序。

I have a problem to connect to the SQL Server. 我在连接到SQL Server时遇到问题。

On localhost this connection string works fine: 在本地主机上,此连接字符串可以正常工作:

 @"Data Source=LOCAL-HP;Initial Catalog=OnlineVertrag;Integrated Security=True";

I'm using a similar connection string on the server: 我在服务器上使用了类似的连接字符串:

@"Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=OnlineVertrag;Integrated Security=True";

but nothing happens over there. 但那边什么都没发生。

Here is my project which I am trying to connect: http://www.hotcont.eu/OnlineVertrag/Home 这是我尝试连接的项目: http : //www.hotcont.eu/OnlineVertrag/Home

Based on your comments, your SQL instance on the server has a username/password combination. 根据您的评论,服务器上的SQL实例具有用户名/密码组合。 You cannot use the integrated security connection for a SQL Server connection requiring SQL authentication. 您不能将集成安全连接用于需要SQL身份验证的SQL Server连接。

Using the login information provided to you by your host, you should update your connection string to the following: 使用主机提供给您的登录信息,您应该将连接字符串更新为以下内容:

Server=MYSERVER\SQLEXPRESS;Database=OnlineVertrag;User Id=myUsername;
Password=myPassword;

Taken from ConnectionStrings.com 取自ConnectionStrings.com

EDIT 编辑

Ok - I think I know what you are dealing with now. 好的-我想我知道您现在在处理什么。 You have a virutal machine hosted on a large hosting provider -> meaning that you have control over the machine itself (aka Remote Desktop Management or something?) 您有一台虚拟的计算机托管在大型托管服务提供商上->这意味着您可以控制计算机本身(又名“远程桌面管理”或其他?)

The SQL connection string that I provided is for use with SQL server accounts -> meaning those that you actually create within SQL server itself. 我提供的SQL连接字符串用于SQL Server帐户->表示您实际上在SQL Server本身中创建的那些。 The SQL connection string that you provided uses the current logged in user's user account information from Windows to connect to SQL. 您提供的SQL连接字符串使用Windows中当前登录的用户的用户帐户信息来连接到SQL。

So here is the disconnection between localhost and the virtual server. 因此,这是本地主机和虚拟服务器之间的断开连接。 When you are running on localhost, I am going to assume that you are using the built in web server to Visual Studio or some equivalent. 当您在localhost上运行时,我将假设您正在使用Visual Studio或某些等效版本的内置Web服务器。 Most often, during debugging, the web application is running under the Logged in user of the machine - aka: you. 通常,在调试期间,Web应用程序在计算机的“ 登录用户” (又名:您)下运行。 You have permission to your own SQL database, thus no issue. 您拥有自己的SQL数据库的权限,因此没有问题。 BUT...when you deploy your web application to an IIS instance, the web application is no longer running as the logged in user, but rather the identity of the application pool that is your app is a member of. 但是...将Web应用程序部署到IIS实例时,该Web应用程序不再以登录用户身份运行,而是作为您的应用程序的应用程序池的成员身份。 Typically this is something like NETWORKSERVICE. 通常,这类似于NETWORKSERVICE。

You have three options available to you 您有三种选择

  1. Enable and use SQL user accounts for connection from your web application and your SQL server. 启用并使用SQL用户帐户来连接Web应用程序和SQL Server。 If you choose to go this route, you will need to use the connection string I provided above. 如果您选择走这条路线,则需要使用我上面提供的连接字符串。

  2. Login to your SQL server and add the identity of your application pool to the Allowed Users of SQL server and your database. 登录到您的SQL Server,并将您的应用程序池的标识添加到SQL Server的“允许的用户”和您的数据库中。

  3. Change your application pool's identity to an actual user account on the server (BAD IDEA) 将应用程序池的标识更改为服务器上的实际用户帐户(BAD IDEA)

Most web applications go with the first option as it allows you do a few things such as create a distinct SQL user for each application that you host and as well as you can explicitly define permissions for the SQL user to each database that it may need access to (for instance, do not allow the SQL user to DROP tables). 大多数Web应用程序都带有第一个选项,因为它允许您做一些事情,例如为您托管的每个应用程序创建一个不同的SQL用户,以及可以为该SQL用户明确定义其可能需要访问的每个数据库的权限。到(例如,不允许SQL用户删除表)。

EDIT 2 编辑2

The way you are trying to connect sounds like it should be using the Shared Memory Protocol, but it might be trying to connect over TCP/IP. 您尝试连接的方式听起来应该是使用共享内存协议,但它可能正在尝试通过TCP / IP连接。 I forgot this earlier, but most installs of SQL are not setup to listen on the TCP/IP interface on first install. 我之前忘记了这一点,但是大多数SQL安装并未设置为在首次安装时侦听TCP / IP接口。 To check your configuration, click the start button (or orb or whatever Microsoft calls that now) -> All Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager. 要检查您的配置,请单击开始按钮(或orb或Microsoft现在所说的任何命令)->所有程序-> Microsoft SQL Server 2008->配置工具-> SQL Server配置管理器。 This will open a new window with some options on the left hand side. 这将打开一个新窗口,左侧有一些选项。 Click the SQL Server Network Configuration . 单击“ SQL Server Network Configuration Ensure that TCP/IP and Shared Memory is set to enabled. 确保将TCP / IP和共享内存设置为启用。 If a 64 bit install, you should probably do this for both the SQL Server Network Configuration (32 bit) and the SQL Server Network Configuration 如果安装的是64位,则可能应该同时对SQL Server Network Configuration (32 bit)SQL Server Network Configuration

http://msdn.microsoft.com/en-us/library/ms191294.aspx http://msdn.microsoft.com/en-us/library/ms191294.aspx

Try this 尝试这个

Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=OnlineVertrag;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False

I hope this works for you. 希望这对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MVC 3连接字符串到Sql Server 2008 R2无法连接 - MVC 3 connection string to Sql Server 2008 R2 cannot connect ASP.NET MVC3,旨在从SQL Server CE迁移到Server 2008 R2 - ASP.NET MVC3, tyring to migrate from SQL Server CE to Server 2008 R2 使用SQL SERVER 2008 R2的ELMAH for ASP.NET MVC 4 - ELMAH for ASP.NET MVC 4 using SQL SERVER 2008 R2 将ASP.NET MVC应用程序的IIS 7.5应用程序池标识配置为SQL Server 2008 R2上的登录 - Configuring ASP.NET MVC app's IIS 7.5 Application Pool identity as login on SQL Server 2008 R2 将ASP.NET MVC 2应用程序部署到Windows 2008 R2 - Deploy ASP.NET MVC 2 applicatiopn to Windows 2008 R2 尝试连接 SQL 服务器和 ASP.NET MVC mvc 应用程序 - Trying connect SQL Server and ASP.NET MVC mvc app Windows Server 2008 R2上IIS 7.5上的ASP.NET MVC 4无法呈现CSS,JS - ASP.NET MVC 4 on IIS 7.5 on Windows server 2008 r2 does not render css, js 将 ASP.NET MVC 5 应用程序部署到 Windows Server 2008 R2 上的 IIS 7.5 - Deploying ASP.NET MVC 5 Application to IIS 7.5 on Windows Server 2008 R2 如何在Windows Server 2008 R2上安装ASP.net MVC 2? - How to install ASP.net MVC 2 on Windows Server 2008 R2? ASP.NET MVC 3 Windows Server 2008 R2 上的部署 403 错误 - ASP.NET MVC 3 Deployment 403 Error on Windows Server 2008 R2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM