471,893 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

Database Permission

Could someone please tell me how I can trap permission errors in
vb.net on a stored procedure:
ie. Execute permission denied on object 'sel_mytable', database
'mydatabase', owner 'dbo'

I would like to print a message like
response.write("You don't have permission to select on this table") as
opposed to the cryptic message I am receiving.

Thanks in advance
Julie Barnet
Jul 20 '05 #1
3 2220
You can trap a SqlException and translate the error as desired in your code.
VB.Net WinForm example:

Try
sqlCommand.ExecuteReader()
Catch ex As SqlException
Dim PermissionError As Boolean = False
For Each sqlError As SqlError In ex.Errors
If sqlError.Number = 229 Then
PermissionError = True
Exit For
End If
Next sqlError
If PermissionError = True Then
MessageBox.Show("You don't have permission to select on this
table")
Else
MessageBox.Show("Unexpected error: " & ex.ToString())
End If
End Try

--
Hope this helps.

Dan Guzman
SQL Server MVP
"Julie Barnet" <ba*****@pr.fraserpapers.com> wrote in message
news:43*************************@posting.google.co m...
Could someone please tell me how I can trap permission errors in
vb.net on a stored procedure:
ie. Execute permission denied on object 'sel_mytable', database
'mydatabase', owner 'dbo'

I would like to print a message like
response.write("You don't have permission to select on this table") as
opposed to the cryptic message I am receiving.

Thanks in advance
Julie Barnet

Jul 20 '05 #2
I am databinding a datagrid. I tried that and it still doesn't seem
to work. I will paste my code...

Is there something I'm missing?

Public Function BindGrid(ProcName as String, myDataGrid as
DataGrid, cmd as SqlCommand, con as SqlConnection) as Integer
Dim ds As DataSet
Dim da As new SqlDataAdapter()

Try

cmd.CommandText = ProcName
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con

da.Selectcommand = cmd

ds = new DataSet()
da.Fill(ds, "MyTable")

myDataGrid.DataSource=ds.Tables("MyTable").Default View
myDataGrid.DataBind()
return ds.Tables("MyTable").Rows.Count
catch exp as SqlException
HttpContext.Current.Response.Write("Exception3")

End Try
End Function
Jul 20 '05 #3
I ran your code and got the "Exception3" message. What symptoms are you
getting?

--
Hope this helps.

Dan Guzman
SQL Server MVP
"Julie Barnet" <ba*****@pr.fraserpapers.com> wrote in message
news:43**************************@posting.google.c om...
I am databinding a datagrid. I tried that and it still doesn't seem
to work. I will paste my code...

Is there something I'm missing?

Public Function BindGrid(ProcName as String, myDataGrid as
DataGrid, cmd as SqlCommand, con as SqlConnection) as Integer
Dim ds As DataSet
Dim da As new SqlDataAdapter()

Try

cmd.CommandText = ProcName
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con

da.Selectcommand = cmd

ds = new DataSet()
da.Fill(ds, "MyTable")

myDataGrid.DataSource=ds.Tables("MyTable").Default View
myDataGrid.DataBind()
return ds.Tables("MyTable").Rows.Count
catch exp as SqlException
HttpContext.Current.Response.Write("Exception3")

End Try
End Function

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by MW de Jager | last post: by
2 posts views Thread by le0 | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.