DataSource Controls :: How To Use Two Connection Strings On One Data Adapter
Jun 4, 2010or on one sql statement in VS 2008.
How to use two connection strings on one data adapter
or on one sql statement in VS 2008.
How to use two connection strings on one data adapter
This seems like a really silly question, but I've had a search around and I can't find anything about this. I've got a DB connection string that I'm creating in my web.config:-
[Code]....
and
[Code]....
but I need this connection to be read only. I've defined all my linq objects with only gets on their properties, and none of my (MVC) repository classes have .SubmitChanges() methods in them so I'm 99% sure the system can't update this DB, but I would also like to set my DB connection to be RO if at all possible. I realise that ideally this should be done at the SQL server end and the user should be made RO, but that (for various reasons, out of my control) can't be done, so I wanted to lock down my connection as the app mustn't write to the DB.
Is there a "readonly" parameter I can apply to the connection string so that it would throw an error or discard the data if any updates were attempted?
Anyone know if it's possible to inner join tables using two different connection strings? I'm using vb.
View 3 RepliesI have a drop down with different domains(domain_id column) and a textbox (TextBoxComment) for comments. What I am trying to do is select the area, input a comment, click the button and have it save to the db. My connection string errors on compile.
[Code]....
I have a similar problem. I have one Dynamic Data Website and a thousand databases - one database for each customer. HTe databases have the same schema.
After the users log in I want the Dynamic Data Website to point to a database that belongs to that user.
I am using a datasource in the report server where all the reports use that shared datasource while calling the reports from asp.net pages.
Now, as asp.net pages uses the connection string for the databases which is assigned in the web.config file, i want the reports also use the same connection string because you don't need to change on both places( web.config and report server datasource).
how can i get a single row from strongly typed dataset table data adapter in c#?
View 2 RepliesIn my application there are 4 connection strings...from that i want one connectionstring should be default connection string.How to do ?
View 1 RepliesI have a strange issue. I have a XSD file where I have created some TableAdapters. When I have reopened the XSD file it seems like I am not able to create a new table adapter since all the options which will come when I right click on the XSD file are disabled. I have cross verified whether I am on debugging mode but...I was not..(I am not even able to drag and drop an adapter from the left toolbox menu either)I am getting the same issue when I open the same XSD file on somebody else machine but I am able to create TableAdaperts in other XSDs.Can somebody suggest me a solution for this
View 5 RepliesI have created a function that is called when a user wishes to upload a file to the database. The problem I am having is that it won't write the files to the database anymore. This function used to work before I implemented a treeview (which connects to the database). I am struggling to see how the treeview could have cause the file upload to stop working (the error may not even be related to the implementation of the treeview).
The error message I am receiving is: 'Update' is not a member of 'CMS.SiteFilesDSTableAdapters.SiteFilesTableAdapter'.
The code for the upload function is:
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function AddSiteFile(ByVal FileData As Byte(), ByVal FileName As String, ByVal FileDescription As
[code]....
It is throwing the error at: Dim rowsAffected As Integer = Adapter.Update(SiteFiles)
' Return true if precisely one row was inserted, otherwise false
Return rowsAffected = 1
EDIT: I managed to solve this problem by following:
http://www.asp.net/%28S%28pdfrohu0ajmwt445fanvj2r3%29%29/learn/data-access/tutorial-69-cs.aspx
Basically, I had used an Inner Join to gather all the fields, and table adapters don't seem to like them.
INSERT INTO [SiteFiles] ([FileData], [FileName], [FileDescription], [FileType], [FileCreated], [FileCreatedBy]) VALUES (@FileData, @FileName, @FileDescription, @FileType, @FileCreated, @FileCreatedBy)
What is the best practice for encrypting the connectionStrings section in the web.config file when using LINQ TO SQL?
View 2 Repliesi want define connectionSreing in the web.config and then use it for DataContext ConnectionString. i do that : 1. i creat a class in App_Code :(MisaghDB is my database)
partial class MisaghDataContext
{
partial void OnCreated()
{
this.Connection.ConnectionString =
ConfigurationManager.ConnectionStrings["MisaghDBConnectionString"].ConnectionString;
}
// or
public partial class MisaghDataContext
{
public MisaghDataContext() : base (ConfigurationManager.ConnectionStrings["MisaghDBConnectionString"].ConnectionString)
{
OnCreated();
}
}
}
2. Add the connection string to my web.config file:
<configuration>
<connectionStrings>
<add name="MisaghDBConnectionString" connectionString="Data Source=NAZLIN-HP;Initial Catalog=MisaghDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
3. Right click on the DBML file design surface and chose properties. Select "none" for the Connection property.now should i change DBML file designer.cs (Misagh.designer.cs) ? The code should I delete in this file(DBMLfile designer.cs)? this is a part of my DBMLfile designer.cs :
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="MisaghDB")]
public partial class MisaghDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public NorthwindDataContext() :
base(global::WindowsFormsApplication2.Properties.Settings.Default.NorthwindConnectionString, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
............}
I have a C# web service where I need to access a MS SQL DB. I see a way of creating a connection string in IIS and using it in the web application when connecting to the DB. In IIS in Connection strings you specify the name of the connection, server, user n pwd How can I use the name of connection string created in IIS in my c# app.? I am currently using
CustomerInfo
customerinfo = new
CustomerInfo();
// to return
using
(SqlConnection
connection = new
SqlConnection("server=servername;
initial Catalog=eostartest; Integrated Security=SSPI"))
{...
But I would like to use the name of the connection string created in IIS Connection Strings manager. Do I have to add something in the web.config as well?
In IIS 7 you can create database connection strings. I suppose this must be encrypted and best protected by IIS. This is nice, but how do I access it programmatically?
View 7 RepliesI used the following command to encrypt my connection string but an error ocurred,
"The connection name'DatabaseConnectionString1' was not found in the applications configuration or the connection string is empty" How can I encrypt it while keeping the application working? What if I move the encrypted application to another computer? Will it work?
I'm trying to encrypt the connection strings in my web.config. I'm following:
http://msdn.microsoft.com/en-us/library/2w117ede.aspx
however when I get to the part with the command:
aspnet_regiis -pe "connectionStrings" -app "/MyApplication" -prov "MyProvider"
it keeps complaining:
"The configuration for the virtual path '/MyApplication' and site 'Default Web Site' cannot be opened
Failed to map the path '/myapplication'
Failed!
I'm fairly sure I've followed the instructions correctly. I created the project named 'MyApplication' directly in the 'C:' root.
Perhaps I should be following a different set of instructions?
In my DAL i have more than 100 methods/Function, each and every method am opening the sqlconnection and closing the connection, this is taking too much of time to establish the connection at every time. So what i expect is one common class will create the SqlConnection that will check if the connection is Broken or Closed then create the connection again else return the connection, how to do this(Also i would like to apply ConnectionPooling).
View 7 RepliesI was asked to design a asp.net website with modular programming, yet I have no clue what that actually means, does he mean structured programming?, everything I've found on modular programming has no relation to an asp.net website (or its code behind). Could someone explain what it means if: I have a database connection on each page of the website rather than having the connection string in the global or webconfig page? Does this mean structured or modular? In what terms could you achieve modular programming with a website that has no loadable modules? Its just a site with a few connection strings and some clever programming to do some fancy html?
I've seen other posts about webparts and cms but really have no understanding of them? Are they relevant? Unsure. My site is just a social network site that allows some one to login/create account with the website then go to his own profile and display things about himself that are saved to our database. Nothing in it requires modules as far as I can tell? So it makes me think is it a different method of actually "programming" writing the code? i.e is it stored in a different manner is it refrenced in a different manner is called in a different manner?
I'm using the template posted in this thread to generate C# enums from a couple of lookup tables in SQL Server within a class library that contains my DAL.
At the moment, I have the connection string used by the templates embedded an a template include file in the class library. Is there a convenient way to have the template grab the connection string from the main project (WAP)'s web.config without having to include a physical path? Or is there a better way to approach this?
I've also considered creating a SQL CLR assembly which returns a table-valued function containing the enum contents (which would then be defined in C#, not in the database), but I'm not sure what the performance hit would be. Whether or not it's significant will obviously be application-dependent but I'd hate to charge down a crappy path if it's a know best-avoid-this approach.
How Can We Have two Connection Strings In Web.Config And Switch Betweeen Them In Code Behind? when i add two connention strings in web.config so an error appears that tells us u cann't add two connection strings in web.config. i want the upper job because i have 2 databases and i want transfer data from another to the other one.
View 4 RepliesOn most of my asp.net web application I have at least 4 computers that I am constantly moving my application around to. My development PC at work, at home, a test web server for others to test then finally the production server. In all cases I am using a MS-SQL database that would be on a minimum of 3 (usually 4) different sql servers. I am constantly changing the connection string(s) in the web.config file. Now I have just learned about Entity Frameworks which apparently requires its own connection string.
As far as I know the only references to the connection string(s) would be the web.config settings for the asp.net membership and role provider settings and now the entity framework object. So I was hoping I could do some coding in the Global.asax unit under some function and "detect" which server I am running on maybe by its name or something that would be both constant and unique on all machines. Then programmatically configure the membership provoders and entity framework object to use the correct connection string.
Encrypt Connection Strings Programmatically in IIS 7
[Code]....
I have a datalayer that uses Linq to SQL , inorder to maintain properly I removed various references to the connection strings to be placed in the same location.
So used the base(ConfigurationSettings.ConnectionString[""].ConnectionString,mappingsource) in the dbml.designer.cs file.
But doing this we have to define the connection strings in the web.config of all the projects that are going to use the data layer.. instead is there a way where in I can define the connection strings in the app.config of the data layer project and have the dbml.designer.cs file to pick from this one place?
I have just deployed my entire website onto my hosting provider. My databases worked fine whilst I was testing the website on the local host. They use Plesk Control Panel. Here is my connection string:
Data Source=.SQLEXPRESS;AttachDbFilename|DataDirectory|ASPNETDB.MDF";Integrated Security=True;User Instance=True (nothing is omited from this string)
Why isn't this working when the website is online? I get the error Invalid value for key 'attachdbfilename'. I have retargeted my website for .net 2.0 at the providers request because they do not support .net 4.
What is the best way to store/access connection strings and most importantly the URLs for different environments (dev, validation, production). I'm using ASP.NET 1.1.
View 2 Replies