从本地主机运行应用程序时,数据库连接工作正常.从开发服务器登录失败 [英] Database connections work fine when application is run from localhost. Login fails from dev server

查看:63
本文介绍了从本地主机运行应用程序时,数据库连接工作正常.从开发服务器登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序连接到数据库,从用户表中检索用户名,并将其与使用 System.Security.Principal.WindowsIdentity.GetCurrent.Name

I have an application which connects to a database, retrieves a username from a user's table and matches it against the username retrieved with System.Security.Principal.WindowsIdentity.GetCurrent.Name

在我的本地主机上,一切正常.该数据库存在于开发服务器上,但该应用程序位于我的本地主机上.我所有的授权和身份验证技术都运行顺利.

On my localhost, everything works fine. The database exists on the development server but the application lies on my localhost. All of my authorization and authentication techniques are running smoothly.

但是,当我将应用程序发布到开发服务器时,会遇到以下错误.

However, when I publish my application to the development server, I'm faced with the following error.

Cannot open database requested in login 'databaseName'. Login fails.
Login failed for user 'DevelopmentServerName\ASPNET'. 

我无法将手指放在引起这种情况的原因上.任何帮助将不胜感激.

I can't put my finger onto what would cause this. Any help would be greatly appreciated.

谢谢!

这是连接字符串!

  <add name="connectionStringName" connectionString="Initial Catalog=myDatabase;Data Source=DevelopmentServerName;Integrated Security=True"
     providerName="System.Data.SqlClient" />

另外,为了上下文.此身份验证需要获取用户的Windows用户名,并将其与数据库中的用户名进行匹配.用户将具有内置在数据库中的Computername \ Myname用户名(即,如果他们被授权使用程序的必需部分,则为该用户名).

Also, for context. This authentication needs to grab the user's Windows username and match it against the username in the database. Users will have the Computername\Myname username built into the database (if they are authorized to use the required section of the program, that is).

再次感谢:)

推荐答案

似乎您的应用程序正在尝试以ASPNET帐户连接到数据库,该帐户可能对开发服务器具有有限的权限,而不是登录到您自己的(您的本地计算机实际上可能正在使用Windows身份).我可以看到两个潜在的解决方案.

It appears that your application is attempting to connect to the database under the ASPNET account, which may have limited permissions on the development server, as opposed to logging in on your own (you local machine may actually be using your windows identity). I can see two potential solutions.

  1. 确保将其添加到web.config文件的system.web部分.

  1. Make sure to add into the system.web section of your web.config file.

如果您的环境确实允许该帐户连接,请与系统管理员和SQL管理员联系,以确保ASPNET帐户具有连接数据库的适当权限.

Check with the system administrator and the SQL administrator to make sure the ASPNET account has proper authorization to connect to the database, if indeed your environment allows this account to connect.

向您的问题添加一些其他代码,例如您的连接字符串也可能会有所帮助.

Adding some additional code to your question, such as your connection string may help things out as well.

好的,您确实在使用IntegratedSecurity,因此通常通过这种设置(使用模拟),需要确保提示您添加用户名和密码以进行身份​​验证.

Okay, you are indeed using IntegratedSecurity, so typically with this kind of setup (using impersonation), you need to make sure you are getting prompted to add your Username and Password to authenticate against.

我们有一个类似的设置,为此,我们必须转到虚拟目录的IIS设置,选择目录安全性"选项卡,然后单击匿名访问和身份验证"控制下的编辑"按钮.

We have a similar setup, and to do this, we have to go to the IIS settings for the virtual directory, select the Directory Security tab, and click the Edit button under Anonymous access and authentication control.

确保未选中匿名访问,并且您很可能需要为您的环境启用正确的身份验证.不幸的是,此处我们仍在使用基本身份验证(明文),但是集成Windows身份验证也可能适用于您.这取决于您的环境.

Make sure Anonymous access is unchecked, and you may will most likely need to enable the proper authentication for your environment. Unfortunately we're still using Basic authentication (clear text) here, but Integrated Windows authentication may will work for you too. It depends on your environment.

我要在主要帖子中添加此评论,因为这似乎起到了作用...

我刚刚找到了这篇文章,它可以帮助您获得正确的配置设置根据IIS环境处理所需的内容.

I just found this post which may help you get the proper configuration setup to handle what you need based on your IIS environment.

这篇关于从本地主机运行应用程序时,数据库连接工作正常.从开发服务器登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆