SQL1092N" ASPNET"不具有执行所请求的命令的权限。基本ODBC调用一个DSN不起作用 [英] SQL1092N "ASPNET" does not have the authority to perform the requested command. Basic ODBC call to a dsn does not work

查看:1947
本文介绍了SQL1092N" ASPNET"不具有执行所请求的命令的权限。基本ODBC调用一个DSN不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

别拍我,这可是我已经张贴此专家交换为好。我只是需要一个答案。这里的问题(是的,我已经搜查,一派,并再次搜索):

我得到的锅炉板ODBC连接code一些非常奇怪的错误。在code连接到DB2(这始终是一起工作喜悦),并从来没有给我过去的问题。这是典型的工作鬼....有一天它只是停止工作。这是发生在中的Windows 2003服务器2个单独的实例。在我的本地机器的code正常工作。在code通过通过IBM DB2 Connect组件的系统DSN设置连接。

一个错误,我得到如下:

  ERROR [08004] [IBM] [CLI驱动程序] SQL1092NASPNET不具有执行请求命令的权限。

这甚至发生后,我把ASPNET帐户在这两个DB2ADMINS和DB2USERS组。我知道DB2USERS组应具有足够的权限,但我想DB2ADMINS只是踢,但他们都没有工作。

在我的其他的applcation,这是使用完全相同的系统DSN(当然,它试图无论如何),该错误消息仅仅是空白的....没有一个。堆栈跟踪如下:

 在System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle,惩戒code沤code)
   在System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection连接,OdbcConnectionString构造,OdbcEnvironmentHandle environmentHandle)
   在System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions选项,对象poolGroupProviderInfo,池类DBConnectionPool,的DbConnection owningObject)
   在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(的DbConnection owningConnection,DbConnectionPoolGroup poolGroup)
   在System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection owningConnection)
   在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的)
   在System.Data.Odbc.OdbcConnection.Open()
   在code类线... // XXX删节
   在窗体类...行XXX //删节

我在一个完全损失就在这里......它的工作....现在它不...

下面是ODBC code:

 字符串DSN = ConfigurationManager.AppSettings.Get(DSN);字符串CON = ConfigurationManager.ConnectionStrings [DSN]的ToString();
// CON计算结果为DSN = MYSYSDSN
OdbcConnection康恩=新OdbcConnection(CON);的OdbcCommand命令=新的OdbcCommand(Constants.SQL_GET_DATA,康涅狄格州);command.CommandType = CommandType.Text;OdbcParameter参数1 =新OdbcParameter(@参数1,param1value);OdbcParameter参数2 =新OdbcParameter(@参数2,param2value);
command.Parameters.Add(参数1);command.Parameters.Add(参数2);OdbcDataReader RDR = NULL;尝试{  conn.Open(); //这里的错误瓦特/以上的堆栈跟踪和一个空消息字符串
  .....


解决方案

你拉在连接字符串/数据源使用的是什么在SQL Server的世界我们称之为信任连接或集成的身份验证。这在测试就好了,因为应用程序将使用您的凭据运行,并且您有权限来访问数据库。

然而,当部署到服务器,该应用运行使用名为ASPNET的特殊的用户帐户。此帐户没有权限来访问你的数据库。因此,有两种方法来解决这个问题:


  1. 给ASPNET帐户权限的数据库。

  2. 使用模拟,使您的应用程序运行具有不同的帐户。

您真的应该选择第二个选项,因为ASPNET帐户是本地计算机帐户,而不是一个域帐户,你不希望被扔左右权限这样。这也解释了为什么添加ASPNET帐户到组无法正常工作 - 这是一个本地帐户,而不是一个域帐户(你可能添加的错误的ASPNET)

不幸的是,我不能帮你设置模拟,我们使用SQL身份验证我在哪里。但我可以给一些指针提高了code你贴:

 字符串DSN = ConfigurationManager.AppSettings.Get(DSN);
字符串CON = ConfigurationManager.ConnectionStrings [DSN]的ToString();
// CON计算结果为DSN = MYSYSDSN使用(康涅狄格州OdbcConnection =新OdbcConnection(CON))
使用(的OdbcCommand命令=新的OdbcCommand(Constants.SQL_GET_DATA,康涅狄格州))
{
    command.Parameters.AddWithValue(@参数1,param1value);
    command.Parameters.AddWithValue(@参数2,param2value);    //不需要的try / catch在这里,除非你在这个级别记录
    //相反,让它为下一级的泡沫可以自行决定如何处理    conn.Open();
    使用(OdbcDataReader RDR = Command.ExecuteReader却())
    {
        而(rdr.Read())
        {
           // 做一点事
        }
    }
} //没有必要在这里呼吁conn.Close() - '使用'块需要照顾它

Don't shoot me for this, but I've posted this on experts-exchange as well. I just need an answer. Here's the question (and yes, i've searched, googled, and searched again):

I'm getting some very strange errors on boiler plate odbc connection code. The code connects to DB2 (which is always a joy to work with) and has never given me issues in the past. This is your typical work ghost....one day it just stopped working. This is happening on 2 separate instances of Windows 2003 servers. On my local machine the code works fine. The code is connecting via a system dsn setup via the IBM DB2 CONNECT components.

One error I get reads:

ERROR [08004] [IBM][CLI Driver] SQL1092N "ASPNET" does not have the authority to perform the requested command.

This happens even after I place the ASPNET account in both the DB2ADMINS and DB2USERS groups. I know the DB2USERS group should have permissions enough, but I tried DB2ADMINS just for kicks, yet neither of them work.

In my other applcation, which is using the exact same system dsn (well, it's trying to anyhow), The error message is simply blank....there isn't one. The stack trace reads:

at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
   at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
   at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.Odbc.OdbcConnection.Open()
   at code class ... line xxx            //abridged
   at form class ... line xxx             //abridged

I'm at an utter loss here...it worked....and now it doesn't...

Here is the odbc code:

String dsn = ConfigurationManager.AppSettings.Get("DSN");

String con = ConfigurationManager.ConnectionStrings[dsn].ToString(); 
// con evaluates to "DSN=MYSYSDSN"


OdbcConnection conn = new OdbcConnection(con);

OdbcCommand command = new OdbcCommand(Constants.SQL_GET_DATA, conn);

command.CommandType = CommandType.Text; 

OdbcParameter param1 = new OdbcParameter("@param1", param1value);

OdbcParameter param2 = new OdbcParameter("@param2", param2value); 


command.Parameters.Add( param1 );

command.Parameters.Add( param2 ); 

OdbcDataReader rdr = null; 

try

{ 

  conn.Open();    //errors here w/ above stack trace and an empty message string
  .....

解决方案

The connection string/data source you're pulling in is using what in the Sql Server world we call a trusted connection or integrated authentication. This works just fine in testing, as the app will run with your credentials, and you have permissions to access the database.

However, when deployed to a server, the app runs using a special user account named "ASPNET". This account does not have permission to access your database. So there are two ways to fix it:

  1. Give the ASPNET account rights to the database.
  2. Use impersonation to make your app run with a different account.

You should really choose the 2nd option, as the ASPNET account is a local machine account rather than a domain account, and you don't want to be throwing permissions around like that. It also explains why adding the ASPNET account to your group doesn't work - it's a local account rather than a domain account (you're probably adding the wrong ASPNET).

Unfortunately, I can't help you set up impersonation as we use sql authentication where I'm at. But I can give some pointers on improving the code you posted:

String dsn = ConfigurationManager.AppSettings.Get("DSN");
String con = ConfigurationManager.ConnectionStrings[dsn].ToString(); 
// con evaluates to "DSN=MYSYSDSN"

using (OdbcConnection conn = new OdbcConnection(con))
using (OdbcCommand command = new OdbcCommand(Constants.SQL_GET_DATA, conn))
{
    command.Parameters.AddWithValue("@param1", param1value);
    command.Parameters.AddWithValue("@param2", param2value); 

    //no need for try/catch here unless you do logging at this level
    // instead, let it bubble up for the next level to decide how to handle

    conn.Open();
    using (OdbcDataReader rdr = command.ExecuteReader())
    {
        while (rdr.Read())
        {
           // do something
        }
    }
}  // no need to call conn.Close() here - 'using' block takes care of it

这篇关于SQL1092N" ASPNET"不具有执行所请求的命令的权限。基本ODBC调用一个DSN不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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