Using Machine.Config Connection String For Data Connection  
Author Message
southwynd





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

I have added a DataSet to my project and then dragged one of the Data Connections from the Server Explorer and dropped it on the DataSet Designer. This gives me a schema to work with.

My problem is that I want to use a connection string from the machine.config file and not the connection associated with the Data Connection I setup in the Server Explorer. When I try to modify the connection, the only options to Log on to the server are 1) Use Windows Authentication and 2) Use SQL Server Authentication. There is no option to use a connection string from the machine.config file.

In my code I am using a table adapter and overriding the default connection string. This works but I think there must be a better way. Here is a snippet out of my code:

.NET Development36  

 
 
Ralph Anthony





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

Have you found a way to get the machine.config connectionStrings to show up in the Visual Studio 2005 IDE yet If so, do you mind sharing your solution with me Like you, I can manually specify them, but I need them to show up as an option in the IDE dropdowns when configuring a drag and drop datasource. Thanks!Ralph
 
 
southwynd





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

I have not found a way to use the machine.config connection strings in the IDE. Manually specifying them is the only way I know.
 
 
Martin Smith





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

I too would like to know how to do this.

It must be a very common thing to want to do.

Come on Microsoft! Any answers


 
 
R.A. Williamson





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

Anyone have an answer Either it's possible or it isn't. What's the solution

 
 
iamunmad





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

Add app.config file to your project.

Add the following lines there

< xml version="1.0" encoding="utf-8" >

<configuration>

<configSections>

</configSections>

<appSettings>

<add key="ConnectionString" value="Data Source=STEALTH\SQL2005;Initial Catalog=TestDatabase;Integrated Security=True"/>

</appSettings>

</configuration>

Then in the GetConnectionString () method use the following lines:

return System.Configuration.ConfigurationManager.AppSettings.Get ( "ConnectionString" );

Before that add System.Configuration.dll reference to the solution.

And if you need to use sql server authentication mode then the connection string will be

Data Source=STEALTH\SQL2005;Initial Catalog=TestDatabase;User Name=sa;Password=sa



 
 
DaveCook





PostPosted: .NET Framework Data Access and Storage, Using Machine.Config Connection String For Data Connection Top

Note the Subject: It is for Machine.config not App.config. Surely not many developers would need help adding an app.config, but machine.config is a different matter alltogether.

Sorry, I get annoyed reading all these threads to find a stupid answer at the end of it.