Not include database name in query RRS feed

  • Question

  • I'm giving maintenance to an application that works with typed datasets. We expect to connect the application among three different databases that are owned by different clients.

    Web Application will work exactly the same way for the three clients, so we developed a way to conditionate active connection in order to access the right database.

    But there is a problem with the query generated with MSDataSetGenerator, it includes database name and owner.

    I'm using IBM Informix as DBMS.

    Monday, February 13, 2017 9:56 PM

All replies

  • Hi PabloDFT,

    You could create an .xsd by using the following code. Then, simply add that .xsd to your DataSet project, right-click on the .xsd and choose "Run Custom Tool". This is what will generate the Typed DataSet for you. If that option doesn't show up in your context menu, choose Properties instead and type "MSDataSetGenerator" in the Custom Tool property. After that, any time you make a change to the .xsd in the XML Editor and save the change, the Typed DataSet gets regenerated.

    private void CreateDataSet() { // set up the connection with the database name

    // different clients use differents ConnectionString. string connectionString = this.TestConnection + ";database=" + this.txtDatabaseName.Text; try { // set up the Sql Command and DataAdapter with the Stored Proc name SqlCommand sc = new SqlCommand(this.txtStoredProcName.Text, new SqlConnection(connectionString)); sc.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(sc); // set up the DataSet with the DataSet name DataSet ds = new DataSet(); string[] parts = this.txtDataSetName.Text.Split('.'); ds.DataSetName = parts[0]; // and fill the DataSet da.Fill(ds); // set the filename and write out the schema string filename = this.txtDataSetName.Text; if (parts[parts.Length - 1].ToLower() != "xsd") filename += ".xsd"; ds.WriteXmlSchema(filename); MessageBox.Show(filename + " successfully created"); } catch (Exception ex) { string msg = ex.Message; if (ex.InnerException != null) msg += "\r\n" + ex.InnerException.Message; MessageBox.Show("The following error occurred: " + ex.Message); } }

    For more information, please refer to:

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, February 14, 2017 3:14 AM
  • @Cole, thanks for "plugging" my blog post. I was just about to post that link.

    ~~Bonnie DeWitt [C# MVP]

    Wednesday, February 15, 2017 3:53 PM