none
linq to sql connection issue RRS feed

  • Question

  • I have the following questions about a linq to sql connection in a C# 2010 web
    form application when comparing the *.dbml file to the web.config file:
    The questions refer to the code listed below:
     
    1. The top of the *.dbml file and the web.config file, there are refernces to
    "TST_DEV" and "TST_DEV2". Can this discrepancy cause problems in the web form
    application? If so, can you tell me how? I am asking this question since most
    references in the production application refer to "TST_DEV" or "TST_DEV2" in the
    same .dbml file and do not mix the references.
     
    2. I do not understand what the
    'name="Dmport.Properties.Settings.DBConnectionString" can be referring to. Can
    you tell me what it is referring to?
     
    3. Are the refernces to "DBConnectionString" in the .dbml file and web.config
    file all related to each other? If so, would you tell me how all these items are
    related to each other? If not, can you tell me what each "DBConnectionString" is
    referring to?
     
    top of .dbml file
    <?xml version="1.0" encoding="utf-8"?><Database Name="TST_DEV"
    Class="HisDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
      <Connection Mode="WebSettings" ConnectionString="Data
    Source=SP9\MSSQL2008;Initial Catalog=TST_DEV2;Persist Security Info=True;User
    ID=xx" SettingsObjectName="System.Configuration.ConfigurationManager.ConnectionS
    trings"
    SettingsPropertyName="DBConnectionString" Provider="System.Data.SqlClient" />
     
    applicable web.config file
     
      <add name="DBConnectionString" connectionString="Data Source=sqldev;Initial
    Catalog=Tst_DV;Persist Security Info=True;User ID=R2;Password=A"
    providerName="System.Data.SqlClient" />
      <add name="Dmport.Properties.Settings.DBConnectionString"
    connectionString="Data Source=sqldev;Initial Catalog=Tst_DV;Persist Security
    Info=True;User ID=R2;Password=A" providerName="System.Data.SqlClient" />
      <add name="TST_DEVConnectionString" connectionString="Data
    Source=sqldev;Initial Catalog=Tst_DV;Persist Security Info=True;User
    ID=R2;Password=A" providerName="System.Data.SqlClient" />
      <add name="TST_DEV2ConnectionString" connectionString="Data
    Source=sqldev;Initial Catalog=Tst_DV;Persist Security Info=True;User
    ID=R2;Password=A" providerName="System.Data.SqlClient" />
    Wednesday, July 11, 2012 3:26 AM

Answers

  • Hi scamper,

    1. The database “TST_DEV” should the same in web.config and *.dbml files, this setting would let you go into the correct database during open the Sql Server connection. This setting would be the same after you map the tables from sql server to *.dbml, and it’s not a good idea to change this value. If “TST_DEV” would be the database which your application interact with then please try to change the following line in *.dbml file:
      ConnectionString="Data Source=SP9\MSSQL2008;Initial Catalog=TST_DEV2;Persist Security Info=True;User ID=xx"
      
      // Change the "TST_DEV2" to "TST_DEV"
      
      ConnectionString="Data Source=SP9\MSSQL2008;Initial Catalog=TST_DEV;Persist Security Info=True;User ID=xx"
    2. This line is for your application to looking for the specified connection string which named “Dmport.Properties.Settings.DBConnectionString” and strode in Web.config file. You could find there is a line of code like following exist in the designer.cs file for *.dbml:
      global::System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString
    3. I guess the SettingsPropertyName is optional for *.dbml.

    Hope this could help you.

    Best Regards,


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us


    Friday, July 13, 2012 9:42 AM
    Moderator