Tuesday, March 27, 2012

Create table from web application

i am creating a model in which the control panel i am building for a web application, i can write sql statements in a textbox and the query will be done in my application. But i am have a problem creating a table.

this error of "Create table permission not granted in the sql server" pops up whenever i want to execute the create table sql statements from my web page.

How can i permit my sql server to allow creation of tables from my web application.

Thanks

It all depends on the type of authentication that you are using for the app. The users of your web app will have to have an account capable of creating tables or whatever else you want them to do. What ever it is make an user account just for them. Please do not give the the sa account or you may be sorry later.|||

i want to know how i can authenticate the user to create the table from the server. I know i have to authenticate the user but what it is procedure to do that. I want to know how i can achieve that in Sql 2000

Thank you

|||Ok, What you can do now is in your connection string use the user and pass that the end user supplies. This will need to be a username and pass that you have supplied to them that is valid for the database. When the user logs in just add their user and pass to session so that you can call it back whenever you need it. Then when you create a connection for that user in your connection string use (string)Session["UserName"] and (string)Session["Password"] for the user and pass. To add their user and pass to the Session just use Session.Add("UserName",txtThetextboxthattheyentertheirusernamein.Text); and Session.Add("Password",txtThetextboxthattheyenteredtheirpasswordin.Text); I would put my connection properties in a class so that you can call them whenever and make your method so that it will accept the user and pass that you need to through it. Like this:
[pre]Public bool DBConnection(string Username,String Password)
{
bool connected = false;
Try
{
your connection params using the strings UserName and Password
connected = true;
}
Catch
{
connected = false;
}
Return connected;
}[/pre]
Then you can check the return value to make sure that they connected and use the connection for whatever you want to process. To call it up just type DBConnection((string)Session["UserName"],(string)Session["Password"])
if you need to check it set the return value to a bool and check for true or false
[pre]
bool didconnect = DBConnection((string)Session["UserName"],(string)Session["Password"])
if (didconnect != false)
{
Whatever stuff you need to run against the db;
}
else
{
Errormessage to the user;
}
[/pre]sql

No comments:

Post a Comment