新手 请教连接数据库问题

wgj1022 2010-07-17 11:38:47
我用VB。net连接SQL server数据库,代码如下:
Dim str As String = "Data Source=(local);Initial Catalog= bgrj;Persist Security Info=True;User ID=sa;Password=123"
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
出现错误:

未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 System.Data.dll 中。

其他信息: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)

SQL语句应该有问题吧,希望前辈指点一下
...全文
114 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wgj1022 2010-07-21
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 xiehuailian 的回复:]
楼主的问题解决了没有
[/Quote]
解决了,我用的是桌面版数据库,说明一下就行了
DevinXie 2010-07-20
  • 打赏
  • 举报
回复
楼主的问题解决了没有
wgj1022 2010-07-17
  • 打赏
  • 举报
回复
Dim str As String = "Data Source=192.168.8.101;Initial Catalog= bgrj;Persist Security Info=True;User ID=sa;Password=123"
这样改了,还是不行啊
wgj1022 2010-07-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wgj1022 的回复:]
引用楼主 wgj1022 的回复:
我用VB。net连接SQL server数据库,代码如下:
Dim str As String = "Data Source=(local);Initial Catalog= bgrj;Persist Security Info=True;User ID=sa;Password=123"
Dim conn As SqlClient.SqlConnectio……
[/Quote]
IP地址还是计算机名?改了,不好用
wgj1022 2010-07-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lester19872007 的回复:]
解决方案!这个问题以前已经见过很多了!网上很多这样的解决方案!
[/Quote]
我也查了不少资料啊,要具体问题具体分析
再就是现在时间紧,没时间系统学了
lester19872007 2010-07-17
  • 打赏
  • 举报
回复
解决方案!这个问题以前已经见过很多了!网上很多这样的解决方案!
FtLover 2010-07-17
  • 打赏
  • 举报
回复
Data Source=(local);Initial Catalog= bgrj;Persist Security Info=True;User ID=sa;

这个填装在你电脑上的实例名称。
wgj1022 2010-07-17
  • 打赏
  • 举报
回复
[Quote=引用楼主 wgj1022 的回复:]
我用VB。net连接SQL server数据库,代码如下:
Dim str As String = "Data Source=(local);Initial Catalog= bgrj;Persist Security Info=True;User ID=sa;Password=123"
Dim conn As SqlClient.SqlConnection
conn = New……
[/Quote]
刚刚配置了一下,是不是把远程连接——本地连接和远程连接然后选第三个,还有什么配置吗?
还是同一个错误啊
兔子-顾问 2010-07-17
  • 打赏
  • 举报
回复
直接用SQL Server Management Studio能连的上么?
外围配置器设置好没有?
wgj1022 2010-07-17
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 lester19872007 的回复:]
只知道该链接字符串有什么用!!
[/Quote]
兄弟,你说的解决方案是什么啊?
我上网找了不少例子了,大同小异,都报这个错,是不是什么地方设置有问题啊,还是没整明白,麻烦再指点指点
lester19872007 2010-07-17
  • 打赏
  • 举报
回复
只知道该链接字符串有什么用!!
lester19872007 2010-07-17
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wgj1022 的回复:]
Dim str As String = "Data Source=192.168.8.101;Initial Catalog= bgrj;Persist Security Info=True;User ID=sa;Password=123"
这样改了,还是不行啊
[/Quote]
这问题,照着解决方案该就是了,这就是根据你的具体问题的解决方案!

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧