Typed DataSet - Does it need to be in a .xsd file?

There is a section in the .xsd file for a typed DataSet in .NET <Connections>that contains a list of any data connections that I used to configure DataTables and TableAdapters.

There are times when I prefer not to have them there. For example, sometimes I prefer to pass the connection string to the user constructor and use this instead of searching in settings, .config, etc.

But it seems that if I delete the connection strings from this section (leaving it empty) or completely delete the section, the DataSet code generation tool will fail. If I do not delete them, the DataSet catches when I put it in another project, because it cannot find the settings for these connection strings.

Is it possible to specify a typed DataSet so as not to worry about any connections? (Obviously, I will need to provide it with a connection if I modify any SQL TableAdapter file or saved procs, but this should be my problem.)

+5
source share
5 answers

It annoyed me too long, and I recently tested some tests. Here is what I came up with. For recording, I am using VS 2008 SP1.

  • Datasets will store information about connection strings, whether you want them or not.
  • You can make sure that datasets will not store passwords in their connection strings.
  • , "connections", .xsd, app.config "connections" .xsd. , "" .

, . xsd , . , , .

+2

/app.config( Visual Studio ) . , public internal ( ). ( \Settings.Designer.cs):

public sealed partial class Settings
{
    [...]
    [global::System.Configuration.DefaultSettingValueAttribute
            ("Data Source=.;Initial Catalog=MyDb;Integrated Security=True;")]
    public string MyConnectionString
    {
        get
        {
            return ((string)(this["MyConnectionString"]));
        }
    }
}

, :

public string MyConnectionString
{
    get
    {
        return ((string)(this["MyConnectionString"]));
    }
    set
    {
        this["MyConnectionString"] = value;
    }
}

, , :

MyDataAccessLibrary.Properties.Settings.Default.MyConnectionString = ...
+1

- TableAdapter.Connection. .

-, <connections> xsd, , , , . <connections> !:)

0

,

, IDE . SERVER.

, .

<add name="MyConnectionString" connectionString="data source=.;Integrated Security=SSPI" providerName="System.Data.SqlClient" />

, , / . - , , . .

0

All Articles