尝试将我的项目文件夹复制到另一个硬盘驱动器时出现问题。我在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