嘗試將我的項目文件夾複製到另一個硬盤驅動器時出現問題。我在Visual Studio中的項目在h:\
中定義,雖然運行exe文件項目沒有任何問題,但將文件夾項目複製到另一個硬盤驅動器時,我有問題將應用程序連接到SQL Server。無法將項目連接到SQL Server數據庫
看到這些截圖:
- http://upload.tehran98.com/img1/f9kio8ssjofg1lhkjdg.jpg
- http://upload.tehran98.com/img1/k6ajdb22xhdjrgcn419.jpg
例如,在登錄表單,並在登錄按鈕我的代碼是:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename=" + Environment.CurrentDirectory + "\Database\Automation.mdf;Database=Automation;Trusted_Connection=Yes;")
s2 = "Select count(*) from Login where UserName = '" & TextBox1.Text & "' and Password = '" & TextBox2.Text & "'"
Dim com As New SqlCommand(s2, conn)
Dim res As Object
conn.Open()
res = com.ExecuteScalar()
conn.Close()
If res = 1 Then
MsgBox("Welcome Dear " + TextBox1.Text, MsgBoxStyle.OkOnly, "Login Successful")
us = TextBox1.Text
If us = "admin" Then
Main.Label4.Text = "ADMINISTRATOR"
Else
Main.Label4.Text = "USER"
us = TextBox1.Text
Main.Button3.Enabled = False
Main.Button5.Enabled = False
Main.Button9.Enabled = False
End If
Main.Show()
Me.Hide()
Else
MsgBox("Invalid User OR Password", MsgBoxStyle.Critical, "Attention Please")
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
End If
End Sub
非常感謝你 – 2013-05-08 16:33:16
看看你的定義'SqlConnection'。它包括'相對'路徑。你有沒有把這些物體放在其他硬盤上? – 2013-05-08 16:35:30
這看起來像VBA。你應該用這個標籤更新它。 – Kermit 2013-05-08 16:40:16