Access 2007和SQL Server 2008 R2连接问题

时间:2015-10-11 18:05:39

标签: sql-server vb.net sql-server-2008-r2

我有一个Access 2007表单的应用程序连接到SQL Server 2008 R2数据库 有时当很多用户同时连接时发生错误"他们现在无法连接到DB",如果我重新启动服务器问题就会消失!

当一个用户使用该应用时,不会出现问题。在VB代码下,请检查它并告诉我是否有任何问题,如何解决SQL Server上的并发问题?

Private Sub Save_Click()

DoCmd.SetWarnings False
'--------------------------------- check Nullbility
If IsNull([AD]) = True Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Log Out & Log in again", vbExclamation, "Missing Data"
            Exit Sub
            End If
 If IsNull([Cisco]) = True Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Enter the Agent`s Cisco", vbExclamation, "Missing Data"
            DoCmd.GoToControl "[Cisco]"
            Exit Sub
            End If
  If IsNull([JustificationType]) = True Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Choose the Justification Type from List", vbExclamation, "Missing Data"
            DoCmd.GoToControl "[JustificationType]"
            Exit Sub
            End If
  If IsNull([Just]) = True Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Choose the Justification from List", vbExclamation, "Missing Data"
            DoCmd.GoToControl "[Just]"
            Exit Sub
            End If
  If IsNull([fromdate]) = True Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Enter the DateOfCase", vbExclamation, "Missing Data"
            DoCmd.GoToControl "[fromdate]"
            Exit Sub
            End If
   If IsNull([todate]) = True And Me.JustificationType = "Absent" And Me.Just <> "Move Off" Then
            DoCmd.CancelEvent
            Beep
             MsgBox "Enter Justification`s ""End Date """, vbInformation, "Missing Date!"
            DoCmd.GoToControl "[todate]"
            Exit Sub
            End If
  If IsNull([OldOff]) = True And Me.JustificationType = "Absent" And Me.Just = "Move Off" Then
            DoCmd.CancelEvent
            Beep
             MsgBox "Enter Agent`s Old Off", vbInformation, "Missing Date!"
            DoCmd.GoToControl "[OldOff]"
            Exit Sub
            End If
 If IsNull([Approved]) = True Or [Approved] = "------Select From The List------" Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Choose the Name from the List", vbExclamation, "Missing Data"
            DoCmd.GoToControl "[Approved]"
            Exit Sub
            End If
'---------------------------------From Date < To Date Event
  If ([fromdate] > [todate]) Then
            Beep
            MsgBox "Recheck again as the ""End Date "" before ""Start Date """, vbInformation, "  Wrong Vacation!"
            DoCmd.GoToControl "[fromdate]"
            Exit Sub
            End If
  If IsNull([FromEv]) = True And JustificationType = "Event" Then
            DoCmd.CancelEvent
            Beep
            MsgBox "You Must Specify ""Start"" Time", vbExclamation, "Missing AuthOriginal_Shift_LBLzed Time"
            DoCmd.GoToControl "[FromEv]"
            Exit Sub
            End If
 If IsNull([ToEv]) = True And JustificationType = "Event" Then
            DoCmd.CancelEvent
            Beep
            MsgBox "You Must Specify ""End"" Time", vbExclamation, "Missing AuthOriginal_Shift_LBLzed Time"
            DoCmd.GoToControl "[ToEv]"
            Exit Sub
            End If
   If IsNull([AgentShift]) = True And JustificationType = "Event" Then
   If Me.Just <> "Move Shift" Then
            DoCmd.CancelEvent
            Beep
            MsgBox "Enter Agent`s Shift", vbExclamation, "Missing Data"
            DoCmd.GoToControl "[agentshift]"
            Exit Sub
            End If
            End If





Dim TTCount As Long
Dim FirstTTID As Long
Dim FirstATTID As Long
Dim MoveOff As Variant
Dim Minute_Duration As Long
Dim String_Minute_Duration As String
Dim destinationFile As String
Dim aFSO As Variant

Dim con As Object
Dim cmd As ADODB.Command
Dim ParCisco As ADODB.Parameter
Dim ParDate_Of_Case As ADODB.Parameter
Dim ParMove_Off As ADODB.Parameter
Dim ParAgentShift As ADODB.Parameter
Dim ParFrom As ADODB.Parameter
Dim ParTo As ADODB.Parameter
Dim ParEvent_Duration As ADODB.Parameter
Dim ParCredit_Hours As ADODB.Parameter
Dim ParDebit_Hours As ADODB.Parameter
Dim ParJustification As ADODB.Parameter
Dim ParDescription As ADODB.Parameter
Dim ParCreator As ADODB.Parameter
Dim ParApproved_By As ADODB.Parameter
Dim ParType As ADODB.Parameter
Dim Par_MaxGroupID_Out As ADODB.Parameter
Dim ParFile_Ext As ADODB.Parameter
Dim ParOriginal_Path As ADODB.Parameter
Dim ParNew_Path As ADODB.Parameter
Dim Justification_MaxID_OUT As ADODB.Parameter
Dim ParAttachment_MaxID_Out As ADODB.Parameter

Dim Justification_Cisco As Long
Dim Justification_Date_Of_Case As Variant
Dim Justification_Move_Off As Variant
Dim Justification_AgentShift As String
Dim Justification_From As String
Dim Justification_To As String
Dim Justification_Event_Duration As Long
Dim Justification_Credit_Hours As Long
Dim Justification_Debit_Hours As Long
Dim Justification_Justification As String
Dim Justification_Description As String
Dim Justification_Creator As String
Dim Justification_Approved_By As String
Dim Justification_Type As String
Dim Var_MaxGroupID As Long
Dim JustificationMaxID As Long
Dim AttachmentMaxID As Long




'---------------------------------event duration Time < 23:00 Hours
If Me.JustificationType = "Absent" = True Then
Justification_Event_Duration = 0
Else
Minute_Duration = DateDiff("S", Me.FromEv, Me.ToEv, vbUseSystemDayOfWeek, vbUseSystem)
        If (Minute_Duration > 82800) Then
            DoCmd.CancelEvent
            Beep
            MsgBox "The Event Duration Must be less than 23:00 Hours", vbInformation, "Wrong Duration Time"
            DoCmd.GoToControl "[FromEv]"
            Exit Sub
            End If

Justification_Event_Duration = Abs(Minute_Duration)
End If
'------------------------------------------------------------------

Justification_Cisco = Me.Cisco
Justification_Date_Of_Case = Me.fromdate
Justification_Justification = Me.Just
Justification_Creator = Me.AD
Justification_Approved_By = Me.Approved
Justification_Type = Me.JustificationType



If (Me.Just = "Leave Early(Credit Hour)") Then
Justification_Credit_Hours = Abs(DateDiff("S", Me.FromEv, Me.ToEv, vbUseSystemDayOfWeek, vbUseSystem) * 0.75)
Else
Justification_Credit_Hours = 0
End If

If (Me.Just = "Over Time(Debit Hours)") Then
Justification_Debit_Hours = Abs(DateDiff("S", Me.FromEv, Me.ToEv, vbUseSystemDayOfWeek, vbUseSystem))
Else
Justification_Debit_Hours = 0
End If

If IsNull([FromEv]) = True Then
Justification_From = "00:00:00"
Else
Justification_From = Me.FromEv
End If
If IsNull([ToEv]) = True Then
Justification_To = "00:00:00"
Else
Justification_To = Me.ToEv
End If
If IsNull([AgentShift]) = True Then
Justification_AgentShift = "00:00:00"
Else
Justification_AgentShift = Me.AgentShift
End If
If IsNull([Description]) = True Then
Justification_Description = "Null"
Else
Justification_Description = Me.Description
End If
If IsNull([OldOff]) = True Then
Justification_Move_Off = "1-1-2010"
Else
Justification_Move_Off = Me.OldOff
End If
If ([Just] = "Move Off" And Me.JustificationType = "Absent") Then
TTCount = 1
End If
If ([Just] <> "Move Off" And Me.JustificationType = "Absent") Then
TTCount = [Forms]![Justification]![Count]
End If
If (Me.JustificationType = "Event") Then
TTCount = 1
End If



'Get Max Group ID By Procedure  ----------------------------------------


    Set con = CreateObject("ADODB.Connection")
    con.Open _
            "Provider=sqloledb;Data Source=192.168.4.96;Initial Catalog=ZainJTA;User Id=JTAUser;Password=.369*-+MK;"

             Set cmd = New ADODB.Command
With cmd
  .ActiveConnection = con
  .CommandText = "[dbo].[SP_Justification_Max_Group_ID]"
  .CommandType = adCmdStoredProc

    Set Par_MaxGroupID_Out = .CreateParameter("@Just_Out_MaxGroupID", _
      adInteger, adParamOutput)
  .Parameters.Append Par_MaxGroupID_Out
  .Execute
End With
'Get justification and Attachment IDs ----------------------------------------
Var_MaxGroupID = Par_MaxGroupID_Out.Value

'------------------------------------------------------------------------------------------------------------------------

    con.Close
    Set con = Nothing
    Set cmd = Nothing



'Loop  ----------------------------------------
For Justification_Insert = 1 To TTCount

    Set con = CreateObject("ADODB.Connection")
    con.Open _
            "Provider=sqloledb;Data Source=192.168.4.96;Initial Catalog=ZainJTA;User Id=JTAUser;Password=.369*-+MK;"
             Set cmd = New ADODB.Command

 ' Execute SQL Procedure to Insert Data into SQL Server DB

With cmd
  .ActiveConnection = con
  .CommandText = "[dbo].[SP_Justification_Insert]"
  .CommandType = adCmdStoredProc

  Set ParCisco = .CreateParameter("@Justification_Cisco", _
      adInteger, adParamInput, 10, Justification_Cisco)
  .Parameters.Append ParCisco
    Set ParDate_Of_Case = .CreateParameter("@Justification_Date_Of_Case", _
      adDate, adParamInput, 255, Justification_Date_Of_Case)
  .Parameters.Append ParDate_Of_Case
      Set ParMove_Off = .CreateParameter("@Justification_Move_Off", _
      adDate, adParamInput, 255, Justification_Move_Off)
  .Parameters.Append ParMove_Off
    Set ParAgentShift = .CreateParameter("@Justification_AgentShift", _
      adVarChar, adParamInput, 255, Justification_AgentShift)
  .Parameters.Append ParAgentShift
    Set ParFrom = .CreateParameter("@Justification_From", _
      adVarChar, adParamInput, 255, Justification_From)
  .Parameters.Append ParFrom
    Set ParTo = .CreateParameter("@Justification_To", _
      adVarChar, adParamInput, 255, Justification_To)
  .Parameters.Append ParTo
      Set ParEvent_Duration = .CreateParameter("@Justification_Event_Duration", _
      adInteger, adParamInput, 255, Justification_Event_Duration)
  .Parameters.Append ParEvent_Duration
    Set ParCredit_Hours = .CreateParameter("@Justification_Credit_Hours", _
      adInteger, adParamInput, 255, Justification_Credit_Hours)
  .Parameters.Append ParCredit_Hours
      Set ParDebit_Hours = .CreateParameter("@Justification_Debit_Hours", _
      adInteger, adParamInput, 255, Justification_Debit_Hours)
  .Parameters.Append ParDebit_Hours
    Set ParJustification = .CreateParameter("@Justification_Justification", _
      adVarChar, adParamInput, 255, Justification_Justification)
  .Parameters.Append ParJustification
    Set ParDescription = .CreateParameter("@Justification_Description", _
      adVarChar, adParamInput, 255, Justification_Description)
  .Parameters.Append ParDescription
    Set ParCreator = .CreateParameter("@Justification_Creator", _
      adVarChar, adParamInput, 255, Justification_Creator)
  .Parameters.Append ParCreator
    Set ParApproved_By = .CreateParameter("@Justification_Approved_By", _
      adVarChar, adParamInput, 255, Justification_Approved_By)
  .Parameters.Append ParApproved_By
    Set ParType = .CreateParameter("@Justification_Type", _
      adVarChar, adParamInput, 255, Justification_Type)
  .Parameters.Append ParType
    Set ParGroup_ID = .CreateParameter("@Justification_Group_ID", _
      adInteger, adParamInput, 255, Var_MaxGroupID)
  .Parameters.Append ParGroup_ID
    Set ParFile_Ext = .CreateParameter("@Attachament_File_Ext", _
      adVarChar, adParamInput, 255, TempVars!FileExt)
  .Parameters.Append ParFile_Ext
    Set ParOriginal_Path = .CreateParameter("@Attachament_Original_Path", _
      adVarChar, adParamInput, 255, TempVars!SourceFile)
  .Parameters.Append ParOriginal_Path
    Set ParNew_Path = .CreateParameter("@Attachament_New_Path", _
      adVarChar, adParamInput, 255, Null)
  .Parameters.Append ParNew_Path
  Set ParJustification_MaxID_OUT = .CreateParameter("@Justification_MaxID_OUT", _
      adInteger, adParamOutput)
  .Parameters.Append ParJustification_MaxID_OUT
    Set ParAttachment_MaxID_Out = .CreateParameter("@Attachment_MaxID_Out", _
      adInteger, adParamOutput)
  .Parameters.Append ParAttachment_MaxID_Out

  .Execute
End With
'Get justification and Attachment IDs ----------------------------------------

JustificationMaxID = ParJustification_MaxID_OUT.Value
AttachmentMaxID = ParAttachment_MaxID_Out.Value

If (Justification_Insert) = 1 Then
FirstTTID = JustificationMaxID
FirstATTID = AttachmentMaxID
End If


'Put Attachment File on the share drive ----------------------------------------
If IsNull(TempVars!SourceFile) = False Then
            destinationFile = TempVars!path & "AT\" & "" & FirstTTID & "" & "_" & "" & FirstATTID & "" & "_" & [Cisco] & "_" & _
            Day(Now) & "_" & Month(Now) & "_" & Year(Now) & "." & Right(TempVars!SourceFile, TempVars!FirstCommaPosition - 1)


con.Execute ("Update TBL_Attachment Set TBL_Attachment.Attachament_New_Path= '" & destinationFile & "'" _
           & "where TBL_Attachment.Attachament_Justification_ID=" & JustificationMaxID & "")
End If

    con.Close
    Set con = Nothing
    Set cmd = Nothing

Justification_Date_Of_Case = Justification_Date_Of_Case + 1



If (Justification_Insert = 1) Then

         Set aFSO = CreateObject("Scripting.FileSystemObject")
         aFSO.CopyFile TempVars!SourceFile, destinationFile, True

         End If

Next Justification_Insert




MsgBox "Your Request Rasied Successfully !", vbInformation, "Successes"


Me.IDFrom = FirstTTID
Me.IDTO = JustificationMaxID

T1 = Justification_OT_Duration

'Clear Fields ##############################################################################################


TempVars.Remove ("SourceFile")
TempVars.Remove ("path")
TempVars.Remove ("FirstCommaPosition")
TempVars.Remove ("FileExt")

CommaPosition = Empty
vrtSelectedItem = Empty
destinationFile = Empty
aFSO = Empty
lenfile = Empty
lenreverse = Empty
FirstCommaPosition = Empty
FileExt = Empty
Me.SourceFile = Null

Justification_Cisco = Empty
Justification_Date_Of_Case = Empty
Justification_Move_Off = Empty
Justification_AgentShift = Empty
Justification_From = Empty
Justification_To = Empty
Justification_Credit_Hours = Empty
Justification_Debit_Hours = Empty
Justification_Justification = Empty
Justification_Description = Empty
Justification_Creator = Empty
Justification_Approved_By = Empty
Justification_Type = Empty
Justification_Group_ID = Empty
JustificationMaxID = Empty
AttachmentMaxID = Empty
FirstTTID = Empty
FirstATTID = Empty


 Set ParCisco = Nothing
 Set ParDate_Of_Case = Nothing
 Set ParMove_Off = Nothing
 Set ParAgentShift = Nothing
 Set ParFrom = Nothing
 Set ParTo = Nothing
 Set ParCredit_Hours = Nothing
 Set ParDebit_Hours = Nothing
 Set ParJustification = Nothing
 Set ParDescription = Nothing
 Set ParCreator = Nothing
 Set ParApproved_By = Nothing
 Set ParType = Nothing
 Set ParGroup_ID = Nothing
 Set ParFile_Ext = Nothing
 Set ParOriginal_Path = Nothing
 Set ParNew_Path = Nothing
 Set Justification_MaxID_OUT = Nothing
 Set ParAttachment_MaxID_Out = Nothing


 Me.Cisco = Null
 Me.JustificationType = Null
 Me.Just = Null
 Me.fromdate = Null
 Me.todate = Null
 Me.OldOff = Null
 Me.Approved = Null
 Me.Description = Null
 Me.FromEv = Null
 Me.ToEv = Null
 Me.AgentShift = Null



End Sub

这是SQL Server程序

ALTER PROCEDURE [dbo].[SP_Justification_Insert]
    (
       @Justification_Cisco int
      ,@Justification_Date_Of_Case datetime
      ,@Justification_Move_Off datetime
      ,@Justification_AgentShift datetime
      ,@Justification_From datetime
      ,@Justification_To datetime
      ,@Justification_Event_Duration int
      ,@Justification_Credit_Hours int
      ,@Justification_Debit_Hours int
      ,@Justification_Justification varchar(60)
      ,@Justification_Description varchar(255)
      ,@Justification_Creator varchar(80)
      ,@Justification_Approved_By varchar(80)
      ,@Justification_Type varchar(40)
      ,@Justification_Group_ID int
      ,@Attachament_File_Ext nvarchar(10)
      ,@Attachament_Ori_Path nvarchar(255)
      ,@Attachament_New_Path nvarchar(255)
      ,@Justification_MaxID_OUT int out
      ,@Attachment_MaxID_Out int out
      )

AS
BEGIN

    SET NOCOUNT ON;

 -- insert into Justification --
    Insert Into [dbo].[TBL_Justification]
      (
       Justification_Cisco
      ,Justification_Date_Of_Case
      ,Justification_Move_Off
      ,Justification_AgentShift
      ,Justification_From
      ,Justification_To
      ,Justification_Event_Duration
      ,Justification_Credit_Hours
      ,Justification_Debit_Hours
      ,Justification_Justification
      ,Justification_Description
      ,Justification_Creator
      ,Justification_Approved_By
      ,Justification_Type
      ,Justification_Group_ID
      ,Justification_DT
      )

    values 
      (
       @Justification_Cisco
      ,@Justification_Date_Of_Case
      ,@Justification_Move_Off
      ,CONVERT(VARCHAR(50),@Justification_AgentShift,108)
      ,CONVERT(VARCHAR(50),@Justification_From,20)
      ,CONVERT(VARCHAR(50),@Justification_To,20)
      ,@Justification_Event_Duration
      ,@Justification_Credit_Hours
      ,@Justification_Debit_Hours
      ,@Justification_Justification
      ,@Justification_Description
      ,@Justification_Creator
      ,@Justification_Approved_By
      ,@Justification_Type
      ,@Justification_Group_ID
      ,GETDATE()
      )

Set @Justification_MaxID_OUT = SCOPE_IDENTITY()

 -- insert into WFM ID & Resolution --
    Insert Into TBL_WFM(
                        WFM_JustificationID
                       ,WFM_Resolution
                       ,WFM_Status)

          values (
                        @Justification_MaxID_OUT
                       ,'Open'
                       ,'Open');


 -- insert into WFM ID & Resolution --
    Insert Into TBL_attachment(
                   [Attachament_Justification_ID]
                  ,[Attachament_File_Ext]
                  ,[Attachament_Ori_Path]
                  ,[Attachament_New_Path]
                  ,[Attachament_DT])

          values( 
                  @Justification_MaxID_OUT
                 ,@Attachament_File_Ext
                 ,@Attachament_Ori_Path
                 ,@Attachament_New_Path
                 ,GETDATE())

Set @Attachment_MaxID_Out = SCOPE_IDENTITY()

END

0 个答案:

没有答案