Re: Typed DataSets in VS2005



Ar u using "Microsoft.ApplicationBlocks.Data" to access your database.. or
you use SQLHelper directly

As I said before you are missing some thing here.. You have to create a
SqlConnection by reading the values from the config file and assign it to
the SqlCommand so that it will use it when want to connect to the database..

just like below

// Associate the connection with the command
command.Connection = connection;

// Set the command text (stored procedure name or SQL statement)
command.CommandText = commandText;

// If you expect to role back the operation
command.Transaction = transaction;

// Set the command type
command.CommandType = commandType;

// Add parameters that need to pass in to the SP
command.Parameters.Add(parameters);

Then some thing like this would fill data to the dataset

// Create the DataAdapter & DataSet
using( SqlDataAdapter dataAdapter = new SqlDataAdapter(command) )
{

// Add the table mappings specified by the user
if (tableNames != null && tableNames.Length > 0)
{
string tableName = "Table";
for (int index=0; index < tableNames.Length; index++)
{
if( tableNames[index] == null || tableNames[index].Length == 0 ) throw
new ArgumentException( "The tableNames parameter must contain a list of
tables, a value was provided as null or empty string.", "tableNames" );
dataAdapter.TableMappings.Add(tableName, tableNames[index]);
tableName = "Table" + (index + 1).ToString();
}
}

// Fill the DataSet using default values for DataTable names, etc
dataAdapter.Fill(dataSet);

// Detach the SqlParameters from the command object, so they can be used
again
command.Parameters.Clear();
}


I am just writing this just to give you some idea but please do not directly
use them unless you refer to a good online resource about dataset

I don't think that this reply can contain all what you need to know about
dataset/ database.. little bit of googling will find you a resource on this
topic

Nirosh.

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:%23jkiythcHHA.4004@xxxxxxxxxxxxxxxxxxxxxxx
Sorry to follow up on my own post, but a little light may have just lit
up.

The table adapter created with the typed dataset has a Connection
property. If I set that, I might get somewhere. It's too late now,
tonight. I'll try it out in the morning and let the list know how I get
on, in case it helps someone else.



Cheers





Peter



"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:e49cORhcHHA.4872@xxxxxxxxxxxxxxxxxxxxxxx
OK. Here's what I tried.

The hard-coded values are pointing to our development database. So I
created the new table in our live database and created the stored
procedure there as well.

Then I altered the dll.config file that VS2005 puts into the same folder
as the executable to point to the live database, and ran the client.

The data is still returned from the development database.

Can you tell me what I'm doing wrong?


Peter

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:urMwFIhcHHA.3408@xxxxxxxxxxxxxxxxxxxxxxx
OK. So what you're saying is that I need to change the value in, "the
config file". Would this be the dll.config that comes with the typed
dataset? Or are you talking about another config file? If you're
talking about another config file, how is it accessed in code and how is
it passed to the DataSet?

I should say that I changed the dll.config to point to a non-existent
database, then ran the executable expecting to get an error. No error
was generated and the data was retrieved from the development database
(as in the hard-coded strings).


Peter

"Champika Nirosh" <test@xxxxxx> wrote in message
news:OOXFhVgcHHA.4392@xxxxxxxxxxxxxxxxxxxxxxx
To my understanding that value is *only* use for its internal stuff
such as seemlessly synchup with the database.. but not known that it is
used for anything once you deply the solution..I have develop many app
that has auto generated typed dataset and deployed them in many
different env and never bother this value.. I always taken the
connection string via the config file and use it in the dataaccess
layer to communicate with the database..

Nirosh.

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:uijL7PgcHHA.3632@xxxxxxxxxxxxxxxxxxxxxxx
If it was just for its internal use, I wouldn't be bothered. I've
tried it out, and there is no way of changing that setting via a
configuration file once the dll has been deployed (and put in the GAC
in our case) that has worked for me. If you can suggest a way, I'd be
very grateful.


Peter

"Champika Nirosh" <test@xxxxxx> wrote in message
news:%23SfzONgcHHA.2268@xxxxxxxxxxxxxxxxxxxxxxx
So now let's come back again so the designer keep it in the
setting.Designer.cs for its internal use.. so what bother you there?

Nirosh.

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:%23BTOVHgcHHA.4260@xxxxxxxxxxxxxxxxxxxxxxx
Just in case anyone else has any doubts, here's the generated xsd
file (slightly anonymised):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ItregMailDetailsTypedDataSet"
targetNamespace="http://tempuri.org/ItregMailDetailsTypedDataSet.xsd";
xmlns:mstns="http://tempuri.org/ItregMailDetailsTypedDataSet.xsd";
xmlns="http://tempuri.org/ItregMailDetailsTypedDataSet.xsd";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0"
FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout,
AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema"
xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections>
<Connection AppSettingsObjectName="Settings"
AppSettingsPropertyName="aservernamedevConnectionString"
ConnectionStringObject="" IsAppSettingsProperty="True"
Modifier="Assembly" Name="aservernamedevConnectionString (Settings)"
ParameterPrefix="@"
PropertyReference="ApplicationSettings.ItregMailDetailsTypedDataSet.Properties.Settings.GlobalReference.Default.aservernamedevConnectionString"
Provider="System.Data.SqlClient">
</Connection>
</Connections>
<Tables>
<TableAdapter BaseClass="System.ComponentModel.Component"
DataAccessorModifier="AutoLayout, AnsiClass, Class, Public"
DataAccessorName="atablenameTableAdapter"
GeneratorDataComponentClassName="atablenameTableAdapter"
Name="atablename" UserDataComponentName="atablenameTableAdapter">
<MainSource>
<DbSource ConnectionRef="aservernamedevConnectionString
(Settings)" DbObjectName="aservernamedev.dbo.atablename"
DbObjectType="Table" FillMethodModifier="Public"
FillMethodName="Fill" GenerateMethods="Both"
GenerateShortCommands="True" GeneratorGetMethodName="GetData"
GeneratorSourceName="Fill" GetMethodModifier="Public"
GetMethodName="GetData" QueryType="Rowset"
ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
UseOptimisticConcurrency="True" UserGetMethodName="GetData"
UserSourceName="Fill">
<DeleteCommand>
<DbCommand CommandType="Text"
ModifiedByUser="False">
<CommandText>DELETE FROM [dbo].[atablename] WHERE
(([mailbox] = @Original_mailbox) AND ([storage_group] =
@Original_storage_group) AND ([server] =
@Original_server))</CommandText>
<Parameters>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@Original_mailbox" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="mailbox"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@Original_storage_group"
Precision="0" ProviderType="VarChar" Scale="0" Size="0"
SourceColumn="storage_group" SourceColumnNullMapping="False"
SourceVersion="Original">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@Original_server" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="server"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
</Parameters>
</DbCommand>
</DeleteCommand>
<InsertCommand>
<DbCommand CommandType="Text"
ModifiedByUser="False">
<CommandText>INSERT INTO [dbo].[atablename]
([mailbox], [storage_group], [server]) VALUES (@mailbox,
@storage_group, @server);
SELECT mailbox, storage_group, server FROM atablename WHERE (mailbox
= @mailbox)</CommandText>
<Parameters>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@mailbox" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="mailbox"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@storage_group" Precision="0"
ProviderType="VarChar" Scale="0" Size="0"
SourceColumn="storage_group" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@server" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="server"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</InsertCommand>
<SelectCommand>
<DbCommand CommandType="Text"
ModifiedByUser="False">
<CommandText>SELECT mailbox, storage_group,
server FROM dbo.atablename</CommandText>
<Parameters>
</Parameters>
</DbCommand>
</SelectCommand>
<UpdateCommand>
<DbCommand CommandType="Text"
ModifiedByUser="False">
<CommandText>UPDATE [dbo].[atablename] SET
[mailbox] = @mailbox, [storage_group] = @storage_group, [server] =
@server WHERE (([mailbox] = @Original_mailbox) AND ([storage_group]
= @Original_storage_group) AND ([server] = @Original_server));
SELECT mailbox, storage_group, server FROM atablename WHERE (mailbox
= @mailbox)</CommandText>
<Parameters>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@mailbox" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="mailbox"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@storage_group" Precision="0"
ProviderType="VarChar" Scale="0" Size="0"
SourceColumn="storage_group" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@server" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="server"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@Original_mailbox" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="mailbox"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@Original_storage_group"
Precision="0" ProviderType="VarChar" Scale="0" Size="0"
SourceColumn="storage_group" SourceColumnNullMapping="False"
SourceVersion="Original">
</Parameter>
<Parameter AllowDbNull="False"
AutogeneratedName="" DataSourceName="" DbType="AnsiString"
Direction="Input" ParameterName="@Original_server" Precision="0"
ProviderType="VarChar" Scale="0" Size="0" SourceColumn="server"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
</Parameters>
</DbCommand>
</UpdateCommand>
</DbSource>
</MainSource>
<Mappings>
<Mapping SourceColumn="mailbox" DataSetColumn="mailbox"
/>
<Mapping SourceColumn="storage_group"
DataSetColumn="storage_group" />
<Mapping SourceColumn="server" DataSetColumn="server"
/>
</Mappings>
<Sources>
<DbSource ConnectionRef="aservernamedevConnectionString
(Settings)" DbObjectName="aservernamedev.dbo.usp_itreg_roundrobin"
DbObjectType="StoredProcedure" FillMethodModifier="Public"
FillMethodName="FillBy" GenerateMethods="Both"
GenerateShortCommands="True" GeneratorGetMethodName="GetDataBy"
GeneratorSourceName="FillBy" GetMethodModifier="Public"
GetMethodName="GetDataBy" QueryType="Rowset"
ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
UseOptimisticConcurrency="True" UserGetMethodName="GetDataBy"
UserSourceName="FillBy">
<SelectCommand>
<DbCommand CommandType="StoredProcedure"
ModifiedByUser="False">

<CommandText>dbo.usp_itreg_roundrobin</CommandText>
<Parameters>
<Parameter AllowDbNull="True"
AutogeneratedName="" DataSourceName="" DbType="Int32"
Direction="ReturnValue" ParameterName="@RETURN_VALUE" Precision="10"
ProviderType="Int" Scale="0" Size="4"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</SelectCommand>
</DbSource>
</Sources>
</TableAdapter>
</Tables>
<Sources>
</Sources>
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="ItregMailDetailsTypedDataSet"
msdata:IsDataSet="true"; msdata:UseCurrentLocale="true";
msprop:Generator_UserDSName="ItregMailDetailsTypedDataSet"
msprop:Generator_DataSetName="ItregMailDetailsTypedDataSet">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="atablename"
msprop:Generator_UserTableName="atablename"
msprop:Generator_RowDeletedName="atablenameRowDeleted"
msprop:Generator_RowChangedName="atablenameRowChanged"
msprop:Generator_RowClassName="atablenameRow"
msprop:Generator_RowChangingName="atablenameRowChanging"
msprop:Generator_RowEvArgName="atablenameRowChangeEvent"
msprop:Generator_RowEvHandlerName="atablenameRowChangeEventHandler"
msprop:Generator_TableClassName="atablenameDataTable"
msprop:Generator_TableVarName="tableatablename"
msprop:Generator_RowDeletingName="atablenameRowDeleting"
msprop:Generator_TablePropName="atablename">
<xs:complexType>
<xs:sequence>
<xs:element name="mailbox"
msprop:Generator_UserColumnName="mailbox"
msprop:Generator_ColumnVarNameInTable="columnmailbox"
msprop:Generator_ColumnPropNameInRow="mailbox"
msprop:Generator_ColumnPropNameInTable="mailboxColumn">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="storage_group"
msprop:Generator_UserColumnName="storage_group"
msprop:Generator_ColumnVarNameInTable="columnstorage_group"
msprop:Generator_ColumnPropNameInRow="storage_group"
msprop:Generator_ColumnPropNameInTable="storage_groupColumn">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="server"
msprop:Generator_UserColumnName="server"
msprop:Generator_ColumnVarNameInTable="columnserver"
msprop:Generator_ColumnPropNameInRow="server"
msprop:Generator_ColumnPropNameInTable="serverColumn">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1">
<xs:selector xpath=".//mstns:atablename" />
<xs:field xpath="mstns:mailbox" />
</xs:unique>
</xs:element>
</xs:schema>

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:ePvmAEgcHHA.4260@xxxxxxxxxxxxxxxxxxxxxxx
Nirosh. That's what we've done. That's why I'm asking the
question.


Peter

"Champika Nirosh" <test@xxxxxx> wrote in message
news:ubhnSBgcHHA.4260@xxxxxxxxxxxxxxxxxxxxxxx
I am pretty sure that you are doing some thing wrong here.. can you
just create a seperate type dataset and confirm that it add a
connection string too?? Why it need to have a connection string
hradcoded to create a typed dataset for you.. but it you select the
optipon of autocreating the DAL then yes it does add a hardcoded
connection string to the dataset..

Nirosh.

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:uHJh0kfcHHA.3644@xxxxxxxxxxxxxxxxxxxxxxx
Thanks Nirosh, but I'm not sure I understood all that.

I'm only talking about a typed DataSet: not about the entire data
access layer - which we code ourselves and which uses many typed
datasets. At least that was the case until now. If typed
datasets now have the connection string hard coded into them,
we'll definitely not be using them any more - for security
reasons apart from anything else.


Peter

"Champika Nirosh" <test@xxxxxx> wrote in message
news:eLAvOUfcHHA.3960@xxxxxxxxxxxxxxxxxxxxxxx
VSS 2005 support auto generating the dataaccess layer .. and in
that case you are free to change the code where it hardcode the
connection string so that it will read it from a config file
(obviously you have to change the code again if you have to
create/ edit the dataset again.

In my view point the automatically generated code is very good
if you are heading toward a quick concept demo or a working
prototype.. but if you are looking to develop a real extensible
large-scale system, then I rather advice you to have your own
data access layer, indeed you may have some assistance from the
Data access Applcation Blocks or enterprise library. There you
will get that chance of developing a flexible dataaccess layer..
I am telling this with my experience and if you go with the auto
geneated code you will at times drive in to bottleneck of your
code..

Nirosh.


"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:eLioYLfcHHA.2404@xxxxxxxxxxxxxxxxxxxxxxx
Hi all,

This post is sort of tangentially related to my earlier posts
on configuration files for DLLs.

Does anyone know how to create typed DataSets using VS2005's
new DataSet designer, but with the ability to configure the
connection string via a config file? The designer seems to
hard-code the connection string into the dataset itself, which
just can't be right.

The typed DataSets created by VS2005 comes with a dll.config
file that looks as though it's trying to do something like
that, and which is put with the executable at compile time, but
altering the connection string in there doesn't appear to have
any effect. We've seen lots of people asking this question, but
haven't found anyone answering it yet.


Thanks in advance





Peter


























.



Relevant Pages

  • Re: Typed DataSets in VS2005
    ... The hard-coded values are pointing to our development database. ... Or are you talking about another config file? ... I always taken the connection string via ... hradcoded to create a typed dataset for you.. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Typed DataSets in VS2005
    ... SqlConnection by reading the values from the config file and assign it to ... dataset/ database.. ... The table adapter created with the typed dataset has a Connection ... connection string via the config file and use it in the dataaccess ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Typed DataSets in VS2005
    ... I always taken the connection string via the config file ... SELECT mailbox, storage_group, server FROM atablename WHERE (mailbox = ... hradcoded to create a typed dataset for you.. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Typed DataSets in VS2005
    ... The table adapter created with the typed dataset has a Connection property. ... The hard-coded values are pointing to our development database. ... Or are you talking about another config file? ... I always taken the connection string via ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Testing app with Typed Datasets using Test & Production databa
    ... However when I try to change the connection to point to am MSsql database ... with the System.Data.SqlClient provider it throws an exception. ... there should be a connection string. ... typed dataset to run my application against my test database. ...
    (microsoft.public.dotnet.framework.adonet)