Tuesday, November 21, 2006

Local SQL Server 2005 DB and Enterprise DAB

Experiment1
============
Add a SQL database from the Solution explorer using Add New item.
Once you add it , the connection string would be present in the app.config
add name="My.MySettings.Database2ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=DataDirectory\Database2.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"


Use the Enterprise Library DAB and change the default database to point to My.MySettings.Database2ConnectionString
dataConfiguration defaultDatabase="My.MySettings.Database2ConnectionString"

Experiment2
===========

You can also have a .MDF and a .LDF file in the file system as in
C:\Ambarish\Database2.mdf

Change the connection string in the app.config to
add name="My.MySettings.Database2ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Ambarish\Database2.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"

=========================================================



Use the MVC pattern ( here only the controller code is present ) to connect to the DB

============================================
Public Sub GetTable1Data(ByRef ds As DataSet)
Dim db As Database
Dim strCommand As String
Dim dbCommand As DbCommand
Try
db = DatabaseFactory.CreateDatabase()
strCommand = "dbo.uspGetDataTable1"
dbCommand = db.GetStoredProcCommand(strCommand)
ds = db.ExecuteDataSet(dbCommand)
Catch ex As Exception
Throw ex
Finally
db = Nothing
End Try
End Sub


==============================

No comments:

Adda is the Bengali for discussion.Bengali is a language like English.