尝试创建图像表我使用以下代码
CMScomClass.SQLComm = New SqlCommand("EXEC sp_configure 'filestream_access_level', '2' ", CMScomClass.globalPar.SQLConn)
Thread.Sleep(CMScomClass.globalParms.sleepTime)
If CMScomClass.globalPar.SQLConn.State = ConnectionState.Closed Then
CMScomClass.globalPar.SQLConn.Open()
CMScomClass.SQLComm.ExecuteNonQuery()
Else
CMScomClass.SQLComm.ExecuteNonQuery()
End If
CMScomClass.SQLComm = New SqlCommand("RECONFIGURE", CMScomClass.globalPar.SQLConn)
Thread.Sleep(CMScomClass.globalParms.sleepTime)
If CMScomClass.globalPar.SQLConn.State = ConnectionState.Closed Then
CMScomClass.globalPar.SQLConn.Open()
CMScomClass.SQLComm.ExecuteNonQuery()
Else
CMScomClass.SQLComm.ExecuteNonQuery()
End If
CMScomClass.SQLComm = New SqlCommand("CREATE TABLE dbo." & tName & " (" &
FieldName & " UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE , " &
"Image varbinary(MAX) FILESTREAM NOT NULL ) ", CMScomClass.globalPar.SQLConn)
Thread.Sleep(CMScomClass.globalParms.sleepTime)
If CMScomClass.globalPar.SQLConn.State = ConnectionState.Closed Then
CMScomClass.globalPar.SQLConn.Open()
CMScomClass.SQLComm.ExecuteNonQuery()
Else
CMScomClass.SQLComm.ExecuteNonQuery()
End If
CMScomClass.MainWin.OpenCloseImage(sender, e)
当我的代码在
的过程之前CMScomClass.SQLComm.ExecuteNonQuery()
我有以下连接字符串
Data Source=(local)\SQLEXPRESS;Initial Catalog=MSSQLLocalDB;User ID=CMSadmin;Password=pm@ce#7b$
我们在其上看到用户名
Uid = CMSadmin password= pm@ce#7b$
用户也是' LoginUser'和数据库用户,并拥有“sa”的证书。帐户我的服务器。
问题在于我正在尝试执行
CMScomClass.SQLComm.ExecuteNonQuery()
它会抛出错误
用户无权执行此操作。而且我也忘记了我的帐户密码。
相同的代码在之前的程序中运行良好,现在我不知道为什么会出现此错误
答案 0 :(得分:1)
当Login用户不在服务器角色和数据库角色
时,问题就开始了sysadmin
他可以添加数据库程序
CMScomClass.SQLComm = New SqlCommand("EXEC sp_addrolemember 'sysadmin', '" & User & "'", SQLConn)
SQLComm.ExecuteNonQuery()
和服务器程序
CMScomClass.SQLComm = New SqlCommand("EXEC sp_addsrvrolemember '" & User & "', 'sysadmin'", SQLConn)
SQLComm.ExecuteNonQuery()