我用VB.NET编了一个管理系统的程序,可是不知为什么运行时出现“用户‘Sa’登录失败”的问题,显示原因为:未与信任SQL Server连接相关联
有没有哪位能帮帮我这个菜鸟尽快解决这个问题,不胜感激!!
下面是我连接数据库的代码:SQL里需要做些什么吗?
Option Explicit On
Imports System.Data
Imports System.Data.SqlClient
Public Class Class1
Public Shared Connstr As String = "server=localhost;database=OrderSys;uid=Sa;pwd=Sa"
Public Function CreateDataTable(ByVal SQLcmd As String) As DataTable
Dim conn As SqlConnection
Dim myAdapter As SqlDataAdapter
Dim myDataSet As New DataSet
Try
conn = New SqlConnection(Connstr)
conn.Open()
myAdapter = New SqlDataAdapter(SQLcmd, conn)
myAdapter.Fill(myDataSet)
conn.Close()
Return myDataSet.Tables(0)
Catch ex As Exception
End Try
End Function
Public Function updatadatabase(ByVal sqlcmd As String)
Try
Dim conn As SqlConnection, cmd As SqlCommand
conn = New SqlConnection(Connstr)
conn.Open()
cmd = New SqlCommand(sqlcmd, conn)
cmd.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
End Class
我遇到这样的问题,我的机子上有个名为nihao 的服务器,我将连接字符串写成"server=nihao;database=master;uid=Sa;pwd=Sa"的时候可以,写成"server=(local);database=master;uid=Sa;pwd=Sa"也可以了,但是为什么写成"server=localhost;database=master;uid=Sa;pwd=Sa"却不可以了,老是提示sql server不存在或是拒绝访问,
我朋友的c#的代码用"server=localhost;database=master;uid=Sa;pwd=Sa"就可以了,难道vb.net 和c#的连接字符串有什么区别吗?
请问为什么了?
[此贴子已经被作者于2006-10-25 21:56:43编辑过]