sql server存储过程出错
用asp.net 和存储过程操作时:
sql server:
CREATE PROC GetUserName
@UserId INT,
@UserName NVARCHAR(20) OUTPUT -- 要输出的参数
AS
BEGIN
-- 将uName的值赋给 @ostrUserName 变量,即要输出的参数
SELECT @UserName=UserName FROM admin WHERE ID=@UserId
END
GO
asp.net代码:
Dim str As String = "server=localhost;database=newdb; "
Dim con As sqlConnection = New sqlConnection(str)
dim sql as string
sub page_load(sender as object,e as eventargs)
'if not ispostback then
con.open() '出现错误为:SQL Server does not exist or access denied.
dim loadcommand as sqlcommand=new sqlcommand( "GetUserName ",con)
loadcommand.commandtype=commandtype.storedprocedure
loadcommand.parameters.add(new sqlparameter( "@UserId ",sqldbtype.int,4)) loadcommand.parameters( "@UserId ").value=13
loadcommand.executenonquery()
con.close()
response.Write(loadcommand.parameters( "@UserName ").value)
' end if
end sub
------解决方案--------------------Dim str As String = "server=localhost;database=newdb; "
本地sqlserver服务器名一般为“(local)”,还有你没写用户名和密码啊。
------解决方案-------------------- "server=localhost;database=newdb;uid=sa;pwd=密码 "
------解决方案--------------------Dim str As String = "server=(local);database=newdb;uid=sa;pwd=123 "
------解决方案--------------------出现错误为 用户 'sa ' 登录失败。原因: 未与信任 SQL Server 连接相关联。
=======================================================================
你的sa密码是否不对,可以在企业管理器里进行修改