2011-03-25 1 views
0

오류 # -2147467259 ODBC - 호출에 실패했습니다. (출처 : Microsoft Jet 데이터베이스 엔진) (SQL 주 : 3146) (NativeError : -532940753) 가 없습니다 도움말 파일 무슨 일[VBA] 연결된 테이블로 MS Access에서 ADO 쿼리를 만드는 동안 오류가 발생했습니다.

? 이것의 이유는 무엇입니까? ODBC 연결 테이블 (uat env)을 통해 다른 SQL 서버에 쿼리를 만들 수 있지만 서버를로드 할 때이 오류가 발생합니다.

나는 ms 액세스 2000을 사용하고 그 안에 양식을 작성한 후 단추를 눌렀을 때 서버에 쿼리를 작성합니다. 생산성 서버에는 많은 레코드가 있지만 uat 서버에는 3000 레코드 만 있지만 문제는 아니라고 생각합니다.

감사합니다!

Sub extractInboundCdr() 
On Error GoTo Error_Handling 
    Dim conConnection As New ADODB.Connection 
    Dim cmdCommand As New ADODB.Command 
    Dim rstRecordSet As New ADODB.Recordset 
    Dim Err As ADODB.Error 
    Dim strError As String 


    Dim eventPlanCode As String 
    Dim visitedCountry As String 
    Dim startDateTxt As String 
    Dim startDate As Date 
    Dim endDate As Date 
    Dim imsi As String 
    Dim currentMonth As String 
    Dim nextMonth As String 
    Dim currentYear As String 
    Dim nextYear As String 
    Dim temp As Integer 
    Dim i As Integer 
    Dim j As Integer 

    With conConnection 
    .Provider = "Microsoft.Jet.OLEDB.4.0" 
    .ConnectionString = CurrentDb.Name 
    .Open 
    End With 
    conConnection.CommandTimeout = 0 

    With cmdCommand 
    .ActiveConnection = conConnection 
    .CommandText = "SELECT * FROM Opt_In_Customer_Record;" 
    .CommandType = adCmdText 
    End With 

    With rstRecordSet 
    .CursorType = adOpenStatic 
    .CursorLocation = adUseClient 
    .LockType = adLockOptimistic 
    .Open cmdCommand 
    End With 

    If rstRecordSet.EOF = False Then 
     rstRecordSet.MoveFirst 
     Do 
      eventPlanCode = rstRecordSet!Event_Plan_Code 
      visitedCountry = rstRecordSet!Visited_Country 
      startDateTxt = rstRecordSet!start_date 
      imsi = rstRecordSet!imsi 
      currentMonth = Mid$(startDateTxt, 1, 3) 
      currentYear = Mid$(startDateTxt, 8, 4) 


      nextMonth = "" 
      If (currentMonth = "Jan") Then 
       currentMonth = "01" 
       nextMonth = "02" 
      ElseIf (currentMonth = "Feb") Then 
       currentMonth = "02" 
       nextMonth = "03" 
      ElseIf (currentMonth = "Mar") Then 
       currentMonth = "03" 
       nextMonth = "04" 
      ElseIf (currentMonth = "Apr") Then 
       currentMonth = "04" 
       nextMonth = "05" 
      ElseIf (currentMonth = "May") Then 
       currentMonth = "05" 
       nextMonth = "06" 
      ElseIf (currentMonth = "Jun") Then 
       currentMonth = "06" 
       nextMonth = "07" 
      ElseIf (currentMonth = "Jul") Then 
       currentMonth = "07" 
       nextMonth = "08" 
      ElseIf (currentMonth = "Aug") Then 
       currentMonth = "08" 
       nextMonth = "09" 
      ElseIf (currentMonth = "Sep") Then 
       currentMonth = "09" 
       nextMonth = "10" 
      ElseIf (currentMonth = "Oct") Then 
       currentMonth = "10" 
       nextMonth = "11" 
      ElseIf (currentMonth = "Nov") Then 
       currentMonth = "11" 
       nextMonth = "12" 
      ElseIf (currentMonth = "Dec") Then 
       currentMonth = "12" 
       nextMonth = "01" 
      Else 
       GoTo Error_Handling 
      End If 

      temp = Val(currentYear) 
      temp = temp + 1 
      nextYear = CStr(temp) 

      Exit Do 
     Loop Until rstRecordSet.EOF = True 
    End If 


    Set cmdCommand = Nothing 
    Set rstRecordSet = Nothing 
    Set connConnection = Nothing 

    With conConnection 
    .Provider = "Microsoft.Jet.OLEDB.4.0" 
    .ConnectionString = CurrentDb.Name 
    .Open 
    End With 
    conConnection.CommandTimeout = 0 

    Dim thisMonthTable As String 
    Dim nextMonthTable As String 

    thisMonthTable = "dbo_inbound_rated_all_" & currentYear & currentMonth 

    If (currentMonth = "12") Then 
     nextMonthTable = "dbo_inbound_rated_all_" & nextYear & nextMonth 
    Else 
     nextMonthTable = "dbo_inbound_rated_all_" & currentYear & nextMonth 
    End If 

    With cmdCommand 
    .ActiveConnection = conConnection 
    .CommandText = "(SELECT A.IMSI_NUMBER, A.CALL_DATE, A.CALL_TIME, A.VOL_KBYTE, A.TOTAL_CHARGE ,datevalue(A.call_date), A.Service_Code As theDate FROM " & thisMonthTable & " AS A INNER JOIN Opt_In_Customer_Record AS B on A.imsi_number = B.imsi where A.Service_Code = 'GPRS' and Datevalue(A.call_date) >= Datevalue(B.start_date) And Datevalue(A.call_date) < (Datevalue(B.start_date) + val(LEFT(B.event_plan_code, 1)))) " & _ 
        "UNION " & _ 
        "(SELECT A.IMSI_NUMBER, A.CALL_DATE, A.CALL_TIME, A.VOL_KBYTE, A.TOTAL_CHARGE ,datevalue(A.call_date), A.Service_Code As theDate FROM " & nextMonthTable & " AS A INNER JOIN Opt_In_Customer_Record AS B on A.imsi_number = B.imsi where A.Service_Code = 'GPRS' and Datevalue(A.call_date) >= Datevalue(B.start_date) And Datevalue(A.call_date) < (Datevalue(B.start_date) + val(LEFT(B.event_plan_code, 1)))) " & _ 
        "Order by A.IMSI_NUMBER, theDate" 
    .CommandType = adCmdText 
    End With 

    With rstRecordSet 
    .CursorType = adOpenStatic 
    .CursorLocation = adUseClient 
    .LockType = adLockReadOnly 
    .Open cmdCommand 
    End With 


    If rstRecordSet.EOF = False Then 
     rstRecordSet.MoveFirst 
     Do 
      Dim sql As String 
      sql = "insert into IB_CDR values (" 

      For j = 0 To rstRecordSet.Fields.Count - 3 '''''Last 2 fields is not inserted 
       If (j = 3 Or j = 4) Then '''''These fields are number 
        sql = sql & rstRecordSet.Fields(j) & "," 
       Else 
        sql = sql & "'" & rstRecordSet.Fields(j) & "'," 
       End If 
      Next 


      sql = Left(sql, Len(sql) - 1) '''''Remove the last ',' 
      sql = sql & ");" 

      CurrentDb.Execute sql 

      rstRecordSet.MoveNext 

     Loop Until rstRecordSet.EOF = True 
    End If 



    conConnection.Close 
    Set conConnection = Nothing 
    Set cmdCommand = Nothing 
    Set rstRecordSet = Nothing 

    Exit Sub 

Error_Handling: 
For Each Err In conConnection.Errors 
     strError = "Error #" & Err.Number & vbCr & _ 
      " " & Err.Description & vbCr & _ 
      " (Source: " & Err.Source & ")" & vbCr & _ 
      " (SQL State: " & Err.SQLState & ")" & vbCr & _ 
      " (NativeError: " & Err.NativeError & ")" & vbCr 
     If Err.HelpFile = "" Then 
      strError = strError & " No Help file available" 
     Else 
      strError = strError & _ 
       " (HelpFile: " & Err.HelpFile & ")" & vbCr & _ 
       " (HelpContext: " & Err.HelpContext & ")" & _ 
       vbCr & vbCr 
     End If 

     Debug.Print strError 
    Next 

    Resume Next 
Set conConnection = Nothing 
Set cmdCommand = Nothing 
Set rstRecordSet = Nothing 
Exit Sub 

End Sub 

답변

2

이 오류의 가장 일반적인 원인은 Access 데이터베이스가 포함 된 폴더에 대한 잘못된 사용 권한입니다 :

는 쿼리의 일부입니다. 쓰기 권한을 설정해야합니다.

+0

액세스 프로그램의 mdb 파일을 의미합니까? – lamwaiman1988

+1

MDB 파일 (뿐만 아니라 MDB 파일 자체)이 들어있는 폴더를 의미합니다. – anon

+0

permisson은 이미 모든 사람이 완벽하게 제어 할 수 있습니다. 또한 mdb는 모든 사람에게 모든 권한을 부여합니다. – lamwaiman1988

관련 문제