我正尝试使用VB.NET连接到本地安装的SQL Server 2012 Express实例。我已经能够成功连接到使用拖和下降的连接工具,这给了我这个连接字符串的数据库:从VB.NET连接到SQL Server Express 2012(Express)难度
Data Source=mycomputername\sqlexpress;Initial Catalog="my space containing database name";Integrated Security=True
我能成功地测试此连接。现在,我想填充在这个数据库表中的数据网格,所以在“根”(你到底叫这个地方?)项目,我有:
Imports System.Data
Imports System.Data.SqlClient
和表单定义(在任何事件处理程序之前)我有
Private cn As New SqlConnection("Data Source=mycomputername\sqlexpress;Initial Catalog=[my space containing database name];Integrated Security=True;")
Private da As New SqlDataAdapter("select * from MyTable", cn)
Private ds As New DataSet
Private cmb As New SqlCommandBuilder(da)
而这就是火车熄火的地方。我得到的错误:
Cannot open database "MyDatabase" requested by the login.
The login failed. Login failed for user 'MyLogin'.
我已经确保SQL Server Express有远程登录复选框选中,并试图在连接字符串其他变化,但没有运气。想法非常赞赏。
我正在VB.NET中制作一个Windows窗体应用程序,所以我不知道这是否适用 - 错误消息给出了我的正确登录,因为无法连接,所以我认为那部分是好的 – MrBill
@MrBill:您可以使用Management Studio连接到数据库吗? – Luaan
是的,没有麻烦 – MrBill