I cannot connect to SQL Server Express using VB.NET

狂风中的少年 提交于 2019-12-13 01:25:25

问题


Can someone tell me what I am missing? I am using this connection string to connect to my database and still it won't connect:

Dim str As String = "Provider = .NET Framework Data Provider for SQL Server; Data Source=C:\Users\konin\Documents\UHMS\bin\Debug\UHMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

This is the process I used to get the data source:

  1. right-click the database
  2. select properties and click select data source

I hope I am clear enough. Thanks for reading.

Edit:

Error Message is as follows:

unable to connect to database please contact administrator


回答1:


Can you post the error? I've never seen the Data Source connected to a .mdf, only with "AttachDbFilename", you might want to take a look here for details on Connection strings for SQL.




回答2:


Most likely, you'll need something like this:

Dim str As String = "Server=.\SQLExpress;AttachDbFilename=C:\Users\konin\Documents\UHMS\bin\Debug\UHMS.mdf;Database=dbname; Trusted_Connection=Yes;"

You'll still need to have SQL Server Express installed on your machine in order to load this *.mdf file.




回答3:


Assuming yours is a web application... you need to place your file based database in the App_Data folder of your project for it to work. I noticed is located in the Debug folder...



来源:https://stackoverflow.com/questions/2081765/i-cannot-connect-to-sql-server-express-using-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!