February 19, 2005

Someone was looking for the ConnectionString for GoDaddy ASP.NET development. In my code, I use this:
myConnection = New OleDb.OleDbConnection(Application("connectString"))

And in the Global.asax, under Application_Start, I have this:
Application("connectString") = "Provider=SQLOLEDB; Server=myserver; Database=mydatabase; UID=myusername; PWD=mypass;"

Obviously, if you have GoDaddy's service, you have to create your database from your account page, and fill in your values for myserver, mydatabase, myusername and mypass. The myserver value is the fully qualified domain name (ending in secureserver.net) and mydatabase is probably of the form DB_XXXX.
So, if you were looking for help, there ya go (feel free to email me, too).

I put the connectString in as an Application variable so that it would be available from any page, since I need to connect from a variety of pages. ASP.NET has three different objects that are good for storing your variables, the Application object, the Session object and the ViewState object. To store values in any of these objects, you use Session("myvariable"), Application("myvariable") and/or ViewState("myvariable").
The ViewState is stored (and hashed) on the client as a hidden form field [ergo it's not secure, subject to client tampering], but has the added value of being able to store values over long periods of time.
The Session object begins with a user's first request to your ASP.NET application. The session is maintained through a session cookie that IIS exchanges with the client application. It's default timeout is 20 minutes. If the client does not accept session cookies, it won't work for your client. After 20 minutes of inactivity (no requests or form submissions by the client), anything you store in the Session will be thrown away. The Session object values is secure because it's stored on the server, but be aware that it is remotely possible for a user to hijack the session from someone else.
The Application object is good for storing what you might consider to be global values, such as application-wide definitions like a database connectionstring, etc. These types of values might be used in your application frequently, but storing them in an Application() object will allow you to change it in one place.

No comments: