vb.net 用户无权执行此操作。在图像表创建中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38935908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:01:32  来源:igfitidea点击:

User does not have permission to perform this action. in an image table creation

sqlsql-servervb.net

提问by Lefteris Gkinis

Trying to create an image table I use the following code

尝试创建图像表我使用以下代码

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)

When my code is before the process of

当我的代码在进程之前

CMScomClass.SQLComm.ExecuteNonQuery()

I have the following connection string

我有以下连接字符串

Data Source=(local)\SQLEXPRESS;Initial Catalog=MSSQLLocalDB;User ID=CMSadmin;Password=pm@ce#7b$

On which we see the user name

我们在上面看到用户名

Uid = CMSadmin password= pm@ce#7b$

The user is also 'LoginUser' and database user and has credential to 'sa' account of my server.

该用户也是“LoginUser”和数据库用户,并且拥有我服务器的“sa”帐户的凭据。

The problem is when I'm trying to execute

问题是当我试图执行

CMScomClass.SQLComm.ExecuteNonQuery()

it throws the error

它抛出错误

User does not have permission to perform this action. And also I'm loosing the Password of my account.

用户无权执行此操作。而且我丢失了我帐户的密码。

The same code was working fine in previous programs now I don't know why I get this error

相同的代码在以前的程序中运行良好,现在我不知道为什么会出现此错误

采纳答案by Lefteris Gkinis

The problem starts when the Login user is not in the server role and database role

登录用户不在服务器角色和数据库角色时出现问题

sysadmin 

which he may be added with the database procedure

他可以与数据库过程一起添加

CMScomClass.SQLComm = New SqlCommand("EXEC sp_addrolemember 'sysadmin', '" & User & "'", SQLConn)
             SQLComm.ExecuteNonQuery()

and server procedure

和服务器程序

CMScomClass.SQLComm = New SqlCommand("EXEC sp_addsrvrolemember '" & User & "', 'sysadmin'", SQLConn)
               SQLComm.ExecuteNonQuery()