mdf - Cannot connect project to a SQL Server database -
i have problem while trying copy project folder hard drive. project in visual studio defined in h:\
, while run exe file project no problem while copy folder project hard drive have problem connect application sql server.
see these screenshots:
- http://upload.tehran98.com/img1/f9kio8ssjofg1lhkjdg.jpg
- http://upload.tehran98.com/img1/k6ajdb22xhdjrgcn419.jpg
for example in login form , in login button code is:
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim conn new sqlconnection("server=.\sqlexpress;attachdbfilename=" + environment.currentdirectory + "\database\automation.mdf;database=automation;trusted_connection=yes;") s2 = "select count( * ) login username = '" & textbox1.text & "' , password = '" & textbox2.text & "'" dim com new sqlcommand(s2, conn) dim res object conn.open() res = com.executescalar() conn.close() if res = 1 msgbox("welcome dear " + textbox1.text, msgboxstyle.okonly, "login successful") = textbox1.text if = "admin" main.label4.text = "administrator" else main.label4.text = "user" = 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
you need specify database is, can't use environment.currentdirectory. currentdirectory uses path of current working directory. either move database same hard drive or change path database.
http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory.aspx
Comments
Post a Comment