Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a requirement that design an application in C# to execute SQL statement(Same as like Sql query analyzer).This application should work like a read access mode(only select). i don't want to change SQL server user privilege and also there is no restriction in application for execute sql commands.

For example
SQL
Query 1
CREATE TABLE Table(Col1 int,Col2 Int)
INSERT INTO Table(col1,Col2) VALUES(1,2)

Query 2
CREATE TABLE #Table1(Col1 int,Col2 Int)
INSERT INTO #Table1(col1,Col2) VALUES(1,2)

Select * from Table2 as A 
JOIN #Table1 AS B ON A.Col1=B.Col2


As you see above script, if you execute the Query1 application has to throw error, Query2 should work fine.

What I have tried:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;application intent=readonly
Posted
Updated 7-Aug-16 17:06pm
Comments
RossMW 4-Aug-16 4:10am    
If you are only executing select statement why don't you just check the SQL statement for key words to check if it should be run?

in application you need to check string for
update
delete
cretae with # keyword
if string contains above mentioned keyword then application will throw exception "user don't have right for insert update and delete"
 
Share this answer
 
Hi Murugesan,

Here is the query
SQL
SELECT * FROM fn_my_permissions('dbo', 'SCHEMA')

The query result will be "subentity_name", "Permission name".

write a stored procedure to get a permission name and pass a parameter username.(Get this username from application).

//Code in c#

Inside the button click call the stored procedure and check the codition.
If condition is false then display an message box("user doesn't have an access")

Thanks
:)
 
Share this answer
 
Comments
Murugesan Solaiyappan 10-Aug-16 1:11am    
SQL user has a complete permission, i can't change the privilege on sql user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900