Im trying to set a connection string for a my data access layer which is using a value from my Web.Config file from another project.
I create a new class library and add a dbml (Linq to SQL) file and drag a table.
I then add this code to the code file
Partial Public Class MyDataContext
Public Sub New()
MyBase.New(ConfigurationManager.ConnectionStrings("WebConnectionString").ConnectionString, mappingSource)
OnCreated()
End Sub
End Class
This gave me an error "'Public Sub New()' has multiple definitions with identical signatures."
I understood what the error means so did a quick search on a way around it as when i recompiled the project the same problem remained. The way to approach this was/is to override the OnCreated method so i changed the code to:
Private Sub OnCreated()
Me.New(ConfigurationManager.ConnectionStrings("WebConnectionString").ConnectionString, mappingSource)
End Sub
This gave the error "Constructor call is valid only as the first statement in an instance constructor" but not a lot of ways to overcome it (well i see a few C# examples but im sure im an converting it to the correct VB .Net code)
After further research no matter what i do, i dont seem to be able to set the connection string in my DAL which should be using the Web.Config connection string value from another project.
What could i be doing wrong?