How to create a dll which will content the connection string to sql server?

amitava.net

New member
Joined
Nov 16, 2005
Messages
2
Programming Experience
1-3
Hello
I am looking for help in this topic where I want to place a reference or dll file in asp.net project that will be used to create connection to the database that is I will jaust create a new data set and a connection say "con" which will connect to databse.

I am giging the sample code::

Dim con as new Departments.department

' where departments is the dll file and department is the method
Dim sql as string
Dim dset as new dataset

sql="select * from table name"
dset=con.executeSql(sql)

*****************************

Can any one help me???????
 
One solution to "How to create a dll which...."

I have a fully complied ddl as follows:
VB.NET:
Public[SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] cDataMain
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Enum[/COLOR][/SIZE][SIZE=2] DataBaseList
None
Common
Deal
Main
Ohio
Other
DealHist
MainHist
Omega
Retail1
Weighted1
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Enum
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] fConnectToDB([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] dbList [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataBaseList, [/SIZE][SIZE=2][COLOR=#0000ff]Optional[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strConnString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "") [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IDbConnection
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strConnectionString [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] idbConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IDbConnection
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] dbList = DataBaseList.Omega [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]idbConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.Odbc.OdbcConnection
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]idbConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OracleClient.OracleConnection
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] dbList
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Common
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Deal
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Main
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Ohio
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.DealHist
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.MainHist
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.CatTest
strConnectionString = "Data Source=;User Id=;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Other
strConnectionString = strConnString
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Omega
strConnectionString = "Provider=MSDASQL.1;User Id=;Data Source=;Persist Security Info=false;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Retail1
strConnectionString = "Provider=MSDASQL.1;User Id=;Data Source=;Persist Security Info=false;Password=;"
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] DataBaseList.Weighted1
strConnectionString = "Provider=MSDASQL.1;User Id=;Data Source=;Persist Security Info=false;Password=;"[/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] (strConnectionString.Length > 0) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]idbConnection.ConnectionString = strConnectionString
idbConnection.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
[/SIZE][SIZE=2][COLOR=#008000]' Need to implement a error class to catch all of this.
[/COLOR][/SIZE][SIZE=2]Console.WriteLine("Error connecting to " & dbList)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] idbConnection
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function
End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]
As you can see my one dll handles both ODBC and OracleClient. It can be adapted to handle any type of connection you put in the eNum list however. JUST remember to place the new connection type in the if statement.
 
Back
Top