LINQ to SQL connectionstring

前端 未结 6 2197
南旧
南旧 2020-12-09 22:29

I have an application that I want to be able to configure the connection string for my LINQ to SQL. I\'ve tried so many different ways but cannot seem to get it working. I w

6条回答
  •  半阙折子戏
    2020-12-09 23:17

    The DBML class (YourDataContext) has an overloaded constructor which takes ConnectionString, so try instantiating that instead of the default one.Get the connection string from app.config and use that to create the instance.

    YourDataContext context = new  YourDataContext (ConfigurationManager.ConnectionStrings["ConnStringInAppConfig"].ConnectionString)
    

提交回复
热议问题