PDA

View Full Version : Setting up your host for ASP.NET


snowieken
09-15-2006, 12:43 PM
I realize this is a question I could ask my hosting company - and I will if I don't find the answer here - but maybe it's just a standard procedure which someone here can help me with.

It has been over a year since I created anything with ASP.NET, but recently I just started again. Made a simple page retrieving data from an Access database with the DataList control. It works perfectly on my own server, but taking it online will not work, even though my hosting packet supports ASP.NET and an Access database. This actually illustrates my main problem: I am pretty good at coding but I haven't got a single clue when it comes to servers, networks and hosting. I uploaded my database and my page, but that's basically all I did. I know I should be doing something else as well, but I have no clue. Any ideas? Should there be a specific folder I have to put things in, should there be any specific setting I have to adjust?

I don't get an error report as the customerrors mode in web.config is turned to RemoteOnly, and I suspect I can't do anything about that without contacting my host.

vinyl-junkie
09-16-2006, 02:35 AM
I setup some code in my web.config file to point to either my PC at work, my PC at home, or my production web server:

<appSettings>
<add key="cdtrust.lni" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Pat's Documents\cdtrust\CDTrust.mdb;Persist Security Info=False" />
<add key="cdtrust.home" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Pat\My Documents\Website\techtipscentral.net\ASPDotNet\cdtrust\CDTrust.mdb;Persist Security Info=False" />
<add key="cdtrust.prod" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Pat's Documents\cdtrust\CDTrust.mdb;Persist Security Info=False" />
</appSettings>

My database connection class that access the above code looks like this:

Imports System.Data.OleDb
Public Class DBConnection

Public Shared Function getDBConnectionString() As String
Const MACHINENAME_LNI As String = "LNIDPC073688D"
Const MACHINENAME_HOME As String = "PATNEW"
Const MACHINENAME_PROD As String = ""

Select Case System.Environment.MachineName
Case MACHINENAME_LNI
Return ConfigurationSettings.AppSettings("cdtrust.lni")
Case MACHINENAME_HOME
Return ConfigurationSettings.AppSettings("cdtrust.home")
Case MACHINENAME_PROD
Return ConfigurationSettings.AppSettings("cdtrust.prod")
Case Else
Throw New ApplicationException(System.Environment.MachineName)
End Select
End Function

Public Overloads Shared Sub ExecuteCommand(ByVal connection As OleDbConnection, ByVal command As OleDbDataAdapter, ByVal dataSet As DataSet, ByVal tableName As String)
Try
connection.Open()
command.Fill(dataSet, "cdtrust")
Finally
connection.Dispose()
End Try
End Sub

Public Overloads Shared Sub ExecuteCommand(ByVal sql As String, ByVal dataSet As DataSet, ByVal tableName As String)
Dim mAdabter As New OleDbDataAdapter
Dim mConnectionString As String = getDBConnectionString()
Dim mOleDBConnection As New OleDbConnection(mConnectionString)
mAdabter = New OleDbDataAdapter(sql, mOleDBConnection)
ExecuteCommand(mOleDBConnection, mAdabter, dataSet, tableName)
End Sub

Public Shared Function IsConnected(ByVal mOleDBConnection) As Boolean
If Not (mOleDBConnection Is Nothing) Then
If mOleDBConnection.State() = ConnectionState.Open Then
Return True
End If
End If
Return False
End Function

End Class

With your code setup like this, you don't need to make any changes to it when you port it between the different servers.

Hope you find this useful. :)

If you don't know what it is, you'll need to contact your web host for your database connection string information, but I thought I'd give you an easy way to work with your code once you find out what you need.