Okay, I am using a login form and it has been working for a while now. Whenever I tried running it yesterday and today, it failed. This is the error im encountering. SQLException was unhandled - Database 'T:\AITP NEW\AITP\AITP\users.mdf' already exists.
Could not attach file 'C:\AITP NEW\AITP\AITP\users.mdf' as database 'users'. My code is below. What would be causing this?


VB Code:
  1. Public Class Login
  2.     ' Place this code under your Public Class.  If your form name is Login, then place it under Public Class Login
  3.     Inherits System.Windows.Forms.Form
  4.     Dim iCount As Integer ' this integer is declared to help count the number of imes a user tried to login.
  5.     Dim frmMain As New Form1 ' this line declares a variable that will point the user to the Main Screen upon a successful login.  The second form created is called MainScreen.vb
  6.     'Dim UserLoginInfo As New user
  7.  
  8.     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loginbtn.Click
  9.         Dim theConnectionString As New SqlClient.SqlConnection("Server=.\SQLExpress;AttachDbFilename=C:\AITP NEW\AITP\AITP\users.mdf;Database=users;Trusted_Connection=Yes;")
  10.         Dim theSqlCommand As New SqlClient.SqlCommand("SELECT [User_LoginType] FROM [Users] WHERE [User_Name] = @username AND [User_Password] =@password", theConnectionString)
  11.  
  12.         Dim theUsername As New SqlClient.SqlParameter("@username", SqlDbType.VarChar, 50)
  13.         theUsername.Value = Usernametxbx.Text
  14.         Dim thePassword As New SqlClient.SqlParameter("@password", SqlDbType.VarChar, 50)
  15.         thePassword.Value = Passwordtxbx.Text
  16.         theSqlCommand.Parameters.Add(theUsername)
  17.         theSqlCommand.Parameters.Add(thePassword)
  18.  
  19.         'open the connection
  20.         theSqlCommand.Connection.Open()
  21.         Dim theDataReader As SqlClient.SqlDataReader = theSqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
  22.  
  23.         Dim theLoginType As Object = Nothing
  24.         If theDataReader.HasRows Then
  25.             theDataReader.Read()
  26.             'the user exists!! Lets get the logintype:
  27.             theLoginType = theDataReader("User_LoginType")
  28.             'UserLoginInfo.UserType = theLoginType
  29.             'UserLoginInfo.user_info = theUsername
  30.         End If
  31.         theSqlCommand.Connection.Close()
  32.  
  33.  
  34.  
  35.         If theLoginType = "admin" Then
  36.             If accesslvlcmbx.SelectedItem = "User" Then
  37.                 Me.Hide()
  38.                 frmMain.Show()
  39.                 Me.Close()
  40.             ElseIf accesslvlcmbx.SelectedItem = "Administrator" Then
  41.                 Me.Hide()
  42.                 admin.Show()
  43.                 Me.Close()
  44.             ElseIf accesslvlcmbx.SelectedItem = "" Then
  45.                 MessageBox.Show("You need to select a login type.", "LoginType", MessageBoxButtons.OK, MessageBoxIcon.Error)
  46.             End If
  47.         ElseIf theLoginType = "user" Then
  48.             If accesslvlcmbx.SelectedItem = "User" Then
  49.                 Me.Hide()
  50.                 frmMain.Show()
  51.                 Me.Close()
  52.             ElseIf accesslvlcmbx.SelectedItem = "Administrator" Then
  53.                 MessageBox.Show("You do not have sufficient access. Please select again.", "LoginType", MessageBoxButtons.OK, MessageBoxIcon.Error)
  54.             ElseIf accesslvlcmbx.SelectedItem = "" Then
  55.                 MessageBox.Show("You need to select a login type.", "LoginType", MessageBoxButtons.OK, MessageBoxIcon.Error)
  56.             End If
  57.         End If
  58.  
  59.     End Sub
  60.  
  61.     Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
  62.         Me.Close()
  63.     End Sub
  64. End Class