2013-01-14 102 views
0

我有一個ASP.net應用程序,我使用了下面的連接字符串:誤差時,我沒有使用ASP應用程序提供商「專案OLE DB提供程序訪問」

<configuration> 
<connectionStrings> 
    <add name="CAF" connectionString="Data Source=pxx-sql2;Initial Catalog=mydb;User ID=DBUser;Password=mypass;Persist Security Info=False;Trusted_Connection=False;" providerName="System.Data.SqlClient"/> 
</connectionStrings> 
</configuration> 

當我閱讀應用程序時,一切正常。但是當我寫的時候,我得到這個錯誤:「對OLE DB提供程序」ADSDSOObject「的臨時訪問已被拒絕,您必須通過鏈接服務器訪問此提供程序。」

提供的堆棧跟蹤:

[SqlException (0x80131904): Ad hoc access to OLE DB provider 'ADSDSOObject' has been denied. You must access this provider through a linked server.] 
    System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412 
    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363 
    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6387805 
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389506 
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538 
    System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +689 
    System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +327 
    MyDBData.Reconcile(HttpRequest req, User u, String assignee) in c:\websites\MyDB\App_Code\MyDBDataReconciler.cs:99 

[Exception: Ad hoc access to OLE DB provider 'ADSDSOObject' has been denied. You must access this provider through a linked server.] 
    MyDBData.Reconcile(HttpRequest req, User u, String assignee) in c:\websites\MyDB\App_Code\MyDBDataReconciler.cs:112 
    EntryEditView.Page_Load(Object sender, EventArgs e) in c:\websites\MyDB\EntryEditView.aspx.cs:50 
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25 
    BasePage.OnLoad(EventArgs e) in c:\websites\MyDB\App_Code\BasePage.cs:19 
    System.Web.UI.Control.LoadRecursive() +71 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064 

除了我不認爲我使用的是「ADSDSOObject」在這個項目中的任何地方。我打開了一個標準的SqlData句柄的連接。

真奇怪的是,這是第四次插入,這是我在提交事務之前的最後一個ExecuteNonQuery(插入)。

這是整個功能。

public void Reconcile(HttpRequest req, User u, string assignee) 
{ 
    SqlConnection conn = new SqlConnection(Config.ConnString); 
    conn.Open(); 
    SqlTransaction transaction = conn.BeginTransaction("UpdateMyDB"); 

    this.master.MyDBMasterID = int.Parse(req.Params["MyDB"]); 
    MyDBLayout MyDBL = new MyDBLayout(this.master.MyDBMasterID); 
    this.master.bexMasterID = int.Parse(req.Params["bex"]); 
    MyDBLayout bexL = null; 
    if (this.master.bexMasterID > 0) 
     bexL = new MyDBLayout(this.master.bexMasterID); 
    SqlCommand cmd = new SqlCommand(); 
    cmd.Transaction = transaction; 
    cmd.Connection = conn; 

    try 
    { 
     int bexForm; 
     if (this.MyDBID == -1) 
     { 
      // Create the blank MyDB 
      cmd.CommandText = @" 
       insert into MyDB_Master(created, branch, client, clientName, submitter, specialist, MyDBDate, MyDBMasterID, bexMasterID) 
        values (getdate(), '', '', '', @submitter, '', getdate(), @MyDBMasterID, @bexMasterID); select @@IDENTITY"; 
      cmd.Parameters.AddWithValue("@MyDBMasterID", req.Params["MyDB"].Trim()); 
      cmd.Parameters.AddWithValue("@submitter", u.LoginName); 
      bexForm = int.Parse(req.Params["bex"].Trim()); 
      if (bexForm != -1) 
       cmd.Parameters.AddWithValue("@bexMasterID", bexForm); 
      else 
       cmd.Parameters.AddWithValue("@bexMasterID", DBNull.Value); 
      MyDBID = (int)((decimal)cmd.ExecuteScalar()); 
     } 
     // Populate the master 
     cmd.CommandText = @" 
       update MyDB_MASTER set branch = @branch, client = @client, clientName = @clientName, 
        specialist = @specialist, MyDBDate = @MyDBDate, 
        MyDBMasterID = @MyDBMasterID, bexMasterID = @bexMasterID, payDate = @MyDBPayDate, method = @method 
       where MyDBID = @MyDBID;"; 
     cmd.Parameters.Clear(); 
     cmd.Parameters.AddWithValue("@MyDBID", MyDBID); 
     cmd.Parameters.AddWithValue("@branch", req.Params["MyDBBranch"].Trim()); 
     cmd.Parameters.AddWithValue("@client", req.Params["MyDBClient"].Trim()); 
     cmd.Parameters.AddWithValue("@clientName", req.Params["MyDBName"].Trim()); 
     cmd.Parameters.AddWithValue("@specialist", req.Params["MyDBSpecialist"].Trim()); 
     cmd.Parameters.AddWithValue("@method", req.Params["MyDBMethod"].Trim()); 

     DateTime MyDBDate = DateTime.MinValue; 
     if (DateTime.TryParseExact(req.Params["MyDBDate"], "MM/dd/yyyy", enUS, DateTimeStyles.AllowWhiteSpaces, out MyDBDate)) 
      cmd.Parameters.AddWithValue("@MyDBDate", MyDBDate); 
     else 
      cmd.Parameters.AddWithValue("@MyDBDate", DateTime.Now); 

     DateTime MyDBPayDate = DateTime.MinValue; 
     if (DateTime.TryParseExact(req.Params["MyDBPayDate"], "MM/dd/yyyy", enUS, DateTimeStyles.AllowWhiteSpaces, out MyDBPayDate)) 
      cmd.Parameters.AddWithValue("@MyDBPayDate", MyDBPayDate); 
     else 
      cmd.Parameters.AddWithValue("@MyDBPayDate", DBNull.Value); 

     cmd.Parameters.AddWithValue("@MyDBMasterID", req.Params["MyDB"].Trim()); 
     bexForm = int.Parse(req.Params["bex"].Trim()); 
     if (bexForm != -1) 
      cmd.Parameters.AddWithValue("@bexMasterID", bexForm); 
     else 
      cmd.Parameters.AddWithValue("@bexMasterID", DBNull.Value); 
     cmd.ExecuteNonQuery(); 

     // Remove old detail 
     cmd.Parameters.Clear(); 
     cmd.CommandText = @"delete from MyDB_detail where MyDBID = @MyDBID"; 
     cmd.Parameters.AddWithValue("@MyDBID", MyDBID); 
     cmd.ExecuteNonQuery(); 

     FixNotes(MyDBID, req, cmd); 

     AddDetail(MyDBID, MyDBL, req, cmd); 
     if (bexL != null) 
      AddDetail(MyDBID, bexL, req, cmd); 

     cmd.Parameters.Clear(); 
     cmd.CommandText = @"insert into MyDB_history (MyDBID, alteredBy, assignedTo, status) values (@MyDBID, @alteredBy, @assignedTo, @status)"; 
     cmd.Parameters.AddWithValue("@MyDBID", MyDBID); 
     cmd.Parameters.AddWithValue("@alteredBy", u.LoginName); 
     cmd.Parameters.AddWithValue("@assignedTo", assignee); 
     cmd.Parameters.AddWithValue("@status", req.Params["MyDBStatus"]); 
     this.master.assignedTo = assignee; 
     cmd.ExecuteNonQuery();  // <--- Fails here. 

     transaction.Commit(); 
    } 
    catch (System.Exception e) 
    { 
     try 
     { 
      transaction.Rollback(); 
     } 
     catch { } 
     throw new Exception(e.Message, e); 
    } 
} 

這可能是導致此特定錯誤?

+0

你有沒有在'ADSDSOObject'的項目中做全局搜索? – MethodMan

回答

1

ADSDSOObject用於查詢Active Directory。

該錯誤似乎是在SQL服務器中生成的,而不是在您的應用程序中生成的。 我懷疑可能有一個約束或觸發器使用ADSDSOObject對Active Directory驗證傳遞的LoginName(@alteredBy)或受讓人(@assignedTo)。

+0

指責它。我們剛剛將數據庫從一個系統移到另一個系統,沒有人記得在該表上有觸發器在特定條件下發送電子郵件。 –

+0

@clintp不錯! [不要忘記更新文檔:)] – lboshuizen

+0

是的,正在努力。軟件坐在架子上一會兒,當我們偶然發現這些東西時,它們就會被記住。 –

相關問題