为什么用visual studio连接是sql server数据库是总出错?

egg_white 2010-03-26 12:25:58
我输入的代码是:
Imports System.Data.SqlClient
Public Class VbProcedure

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlConnection = New SqlConnection("data source=(CE5DC22C255C4D6/egg);initial catalog=mydb;integrated security=true;uid=sa;pwd=777777")
Dim id As Integer = CInt(TextBox1.Text)
Dim ds As DataSet = New DataSet
Dim adp As SqlDataAdapter = New SqlDataAdapter
conn.Open()
adp.SelectCommand = New SqlCommand
adp.SelectCommand.Connection = conn
adp.SelectCommand.CommandText = "query_user"
adp.SelectCommand.CommandType = CommandType.StoredProcedure
adp.SelectCommand.Parameters.Add("@userid", SqlDbType.Int).Value = CInt(TextBox1.Text)
adp.SelectCommand.ExecuteNonQuery()
adp.Fill(ds, "s")
DataGridView1.DataSource = ds.Tables("s")
End Sub

Private Sub VbProcedure_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

调试报错提示为:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接);
我都在SQL Server 2005 中的外围应用配置中设置了TCP/IP和管道的启用,可SQL Server 2005的网络协议似乎只有shared memory可以正常连接,其它都不行,现在我面对的就是visual studio不能调用SQL数据库啊!!求高手帮忙解决呀,非常感谢了!!!
...全文
357 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
egg_white 2010-04-02
  • 打赏
  • 举报
回复
谢谢各位大虾
porschev 2010-03-31
  • 打赏
  • 举报
回复
走一走。。看一看。。。。
水猿兵团五哥 2010-03-31
  • 打赏
  • 举报
回复

顶楼上
wuyq11 2010-03-26
  • 打赏
  • 举报
回复
开始 -> 所有程序 -> MS SQL Server -> 配置工具 -> Sql server外围应用配置器 ->服务和连接的外围应用配置器 -> 打开MSSQLSERVER节点下的Database Engine节点,选择"远程连接",接下来建议选择”同时使用TCP/IP和named pipes ”,确定后,重启数据库服务.
"Server=.;Database=TEST;Uid=sa;Pwd=sa;"
Data Source=(local);Initial Catalog=TEST;User ID=sa;Password=sa
tjficcbw 2010-03-26
  • 打赏
  • 举报
回复
填充DataGridView1

Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cstring As String = "Data Source=CE5DC22C255C4D6/egg;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;pwd=777777"
Dim con As New SqlClient.SqlConnection(cstring)
Dim sql As String = "select * from table1"
Dim myAdapter As New SqlClient.SqlDataAdapter(sql, con)
Dim myDateset As New DataSet
myAdapter.Fill(myDateset, "dbset")
DataGridView1.DataSource = myDateset.Tables("dbset")


End Sub
End Class

egg_white 2010-03-26
  • 打赏
  • 举报
回复
我的应该是MSDE2005
a12321321321312321 2010-03-26
  • 打赏
  • 举报
回复
data source=.

hava a try.
tjficcbw 2010-03-26
  • 打赏
  • 举报
回复
你是什么库MSDE?
tjficcbw 2010-03-26
  • 打赏
  • 举报
回复
你是什么为msde?

16,721

社区成员

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

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