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.
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
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With