尝试将项目文件夹复制到另一个硬盘驱动器时出现问题。我在Visual Studio中的项目是在h:\
中定义的,而运行exe文件项目没有任何问题,但是当复制文件夹项目到另一个硬盘驱动器时,我将问题连接到SQL Server。
请参阅以下屏幕截图:
例如,在登录表单和登录按钮中,我的代码是:
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
答案 0 :(得分:0)
您需要指定数据库的位置,不能使用 Environment.CurrentDirectory 。 CurrentDirectory使用当前工作目录的路径。因此,要么将数据库移动到同一个硬盘驱动器,要么更改数据库的路径。
http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory.aspx