![]() |
| |||||||
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
| Sponsored Links |
| ||||
| There are several ways to handle this... One way would be to create a class to handle all of your configuration settings and return a string from the web.config: Code: Public Class myConfig
Public Shared ReadOnly Property myConnection() As String
Get
Return ConfigurationManager.ConnectionStrings("yourConStringNameInWebConfig").ConnectionString
End Get
End Property
End Class
Code: Dim conn As SqlConnection = New SqlConnection(myConfig.myConnection) The preferred way, although a little more difficult, is to create a class that inherits from "ConfigurationSection". I won't get into that, but if you're interested, download the sample from here: Wrox::ASP.NET 2.0 Website Programming: Problem - Design - Solution:Book Information and Code Download I also highly recommend the book associated with the code.
__________________ jmurrayhead Did I help you out? Make me popular by clicking the icon!If you found a post helpful, please click the button in the lower right-hand corner of the post.Powered by ASP.Net |
| ||||
| This is how I connect to MySQL db. This doesn't mean it's the best way! web.config Code: <connectionStrings>
<add name="myconn" connectionString="Database=mydb;Data Source=mysql.domain.com;Port=3306;User Id=****;Password=****" />
</connectionStrings>
Code: Imports MySQL.Data.MySqlClient
Imports Company.App.MyBOL
Public Class ConnDAL
Public Shared ReadOnly Property connString() As String
Get
Return System.Configuration.ConfigurationManager.ConnectionStrings.Item("myconn").ConnectionString()
End Get
End Property
End Class
Public Class MyDAL
Public Shared _error As String
Public Shared Function Open(ByVal ref As Integer) As MyBOL
Dim ret As New MyBOL
Dim conn As MySqlConnection
Dim mycommand As MySqlCommand
conn = New MySqlConnection(ConnDAL.connString)
mycommand = New MySqlCommand("SELECT field1,field2,field3,field4,field5 FROM tbl_name WHERE id=?id")
mycommand.Connection = conn
Dim rs As MySqlDataReader
Try
mycommand.Parameters.AddWithValue("id", ref)
conn.Open()
rsgr = mycommand.ExecuteReader()
If rsgr.HasRows Then
rsgr.Read()
ret.property1 = rsgr("field1")
ret.property2 = rsgr("field2")
ret.property3 = rsgr("field3")
ret.property4 = rsgr("field4")
ret.property5 = rsgr("field5")
Else
ret.page_error = "No record Found"
End If
rsgr.Close()
Catch ex As Exception
ret.page_error = ex.Message.ToString
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
Return ret
End Function
End Class
Hope that helps. Last edited by richyrich; May 23rd, 2008 at 08:04 AM. |
| ||||
| The DAL, BOL and BLL are seperate files that contain the Data Access classes, Business Object classes and Business Logic classes respectively. The files are all in the App_Code folder. |
| ||||
| Quote:
ps. can't rep you or JMH yet ![]() |
| ||||
| This is a matter of preference, but I have the following folder structure: App_Code -DAL -BLL -BO I also have a separate class file for each class for better organization. |
| ||||
| Quote:
Does having seperate folders/files have any effect on performance J? |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
| Sponsored Links |
| ASP.NET Resource Index a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer. Free Web Directory Including Chats and Forums Resources, Offer automatic, instant and free directory submissions. | URLZ Web Directory URLZ Web Directory Free Web Directory - Add Your Link The Little Web Directory | Free Web Directory Pegasus free web directory is a free directory organised by categories. Web Directory & SEO Services dirroot web directory |