Deploy a LINQ to SQL Library using different SQL u

2019-08-02 05:17发布

问题:

Thanks to this website I succeed to use a connectionString localized inside a web.config instead of the one provided in the app.config of the library. But my production and my test SQL Server do not have the same SQL user name.

Table(Name="SqlUserName.tableName")]
public partial class tableName : INotifyPropertyChanging, INotifyPropertyChanged
{
    ...
}

When I remove by hand the user name before the table name, it's working. But I still have to problems:

  1. Is it good to do that? Maybe there is a potential flaw I'm not aware of.
  2. If it's a good behavior how can I configure it somewhere? Each time that LINQ will regenerate the dbml, I will loose my modification. I think I can't move it to a partial class as it's an attribute and can't be redefined (I don't want to do it for all the tables also).

Thanks for your help.

回答1:

Use same name for connection strings in web.config local and remote server but use different username and password for them.

I follow this practice and it is perfectly for me.



回答2:

Finally I used the dbo schema for all the tables I created, this way I removed the dependency on the user and LINQ could generate the DBML again without breaking the deployment:

Table(Name="dbo.tableName")]
public partial class tableName : INotifyPropertyChanging, INotifyPropertyChanged
{
    ...
}