p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 3.5 Basics (http://p2p.wrox.com/forumdisplay.php?f=351)
-   -   Making the Page_Load() work (http://p2p.wrox.com/showthread.php?t=73186)

iceman90289 March 9th, 2009 01:56 PM

Making the Page_Load() work
 
okay so my page load for my profile page is supposedly planned as:

1) (on the first time run only) Open a connection to my database and add a table to it.

2) Comment out table creation code

3) add code to check the table for new messages for the signed in user

4) Get the number of these messages and display them in a link saying "{0} new messages"

thats it so far... im stuck on step one:

here is my code, its the first thing in Page_Load()

Code:


// One time use: create database table:
string con = WebConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;
SqlConnection sqlcon = newSqlConnection(con);
SqlCommand cmd = newSqlCommand("CREATE TABLE Messages(Id Int Identity(1,1), Sender NVarChar(11), Recievers NVarChar, MessageBody NVarChar(1500), MessageSubject NVarChar(25), status Int");
cmd.Connection = sqlcon;
using (sqlcon)
{
sqlcon.Open();
cmd.ExecuteNonQuery();
sqlcon.Close();
}

now when i run this code... it complains that i dont have permission to do this.

dparsons March 9th, 2009 02:49 PM

We talked about this outside of the boards so i wont rehash the convo. The simple answer is that the account that you use to access SQL server is probably only a datareader/writer which means it can read and write data to and from the database. This is a security meause since you dont want to expose powerful sql commands to the general populace.

You will need to talk to your host about the best way to proceed.

Lee Dumond March 9th, 2009 03:59 PM

What is the security message exactly?

I can think of two things that could be happening.

First, I have heard of hosters who run in medium trust not allowing access to WebConfigurationManager. Weird, I know, but it does happen. The workaround for this is usually to use ConfigurationManager instead.

Second, the ASP.NET worker process doesn't have permission to run DDL commands. This is probably more likely. Like Doug said, you'll have to see if you can grant dbo permissions to the ASP.NET account.

iceman90289 March 9th, 2009 07:19 PM

thanks guys

iceman90289 March 11th, 2009 03:28 AM

here is their process: upload db file to db folder,

attach db file... when you need to update the db file, detach and re upload. and attach again...

sounds fun... so... yeah i had to work out some things like adding two connection strings in the web.config, one for developing on my local pc and the other for the website. I have to use SQL Management studio to do execute the queries. that doesnt seem like an issue to me... i got kind of a feel for that program now.

anyways this was a fun mini-adventure :) whats cool about knowing nothing due to my experience level is that i can learn stuff every day. haha.

Imar March 11th, 2009 04:12 PM

Quote:

whats cool about knowing nothing due to my experience level is that i can learn stuff every day.
I don't think that newbies have that exclusive right.... ;-) I think it applies to all of us. I know it does to me.....

Cheers,

Imar

dparsons March 11th, 2009 04:42 PM

Quote:

Originally Posted by Imar (Post 236795)
I think it applies to all of us. I know it does to me.....

Agreed! =]

-Doug

iceman90289 March 11th, 2009 09:40 PM

true... nobody knows everything.

but the people with 10k+ forum points hide that fact pretty well. haha

i never hear an "idk" from those guys.. i might hear "google it" but thats because a lot of my questions are asked out of laziness. and i think people like me should get used to googling the error messages before asking someone what they should do.. i mean the answer can be found as quickly as if someone gave it to you in some cases.

talk about an off topic post haha

Lee Dumond March 12th, 2009 04:49 PM

Quote:

Originally Posted by iceman90289 (Post 236709)
anyways this was a fun mini-adventure :) whats cool about knowing nothing due to my experience level is that i can learn stuff every day. haha.

Hey, don't think for a minute that the 10K+ guys don't struggle with stuff every day, same as you do.

Experience doesn't just mean you know more stuff. It means that you have learned how to learn the stuff you don't know.

That means reading code better, navigating through the MSDN better, knowing how to ask better questions, and so on...


All times are GMT -4. The time now is 05:38 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.