Change Connection String From Class Library In Main Application At Runtime?

Jan 16, 2009

You can change the connection string at run-time like this. You make the connection string setting available for writing as a separate property inside the MySettings class:

Partial Friend NotInheritable Class MySettings
Public WriteOnly Property RunTimeConnectionString()
Set(ByVal value)

[code]....

Then, in some place when the application is being initialized (before using any table adapters of typed datasets), write something like:

My.Settings.RunTimeConnectionString = My.Settings.ProductionConnectionString

Where ProductionConnectionString is a simple String setting. It is a User Scope setting so every user can change it (by assigning a value to it, similar to the code above) and save it by calling My.Settings.Save()This code works well for connection strings which were initially created in the main project and stored in it's settings (= app.config file).

The connection string in the app.config actually has a longer name: MyApp.MySettings.MyConnectionString.When you have a connection string stored in the app.config in a class library project, and reference that project in the main project, the app.config files will somehow be merged, so the class library has it's settings.The thing that don't know how to do, is change a setting from the class library at run-time. I could copy the connection string setting from the class library to the main project's app.config. I must keep the same name, which looks something like: MyClassLibrary.My.MySettings.MyConnectionString.Can the same principle I showed above be somehow applied to this second connection string?

View 3 Replies


ADVERTISEMENT

Change Connection String In Class Library Project?

Jun 30, 2011

In my earlier project I was able to change the connection string during the app settings loaded event and it was successfully. When I try to do the same for a code library project, I am not getting the system.configuration.connectionstringsettings to work. Could you please tell if there is a work around for this, or else it is always better to write the sql code instead of depending on the adapters etc.

Additional information: Clients App is WPF with Vb. Database is SQL Server 2008 Code Lib would only be on server, slq connectiona and data retrieving and saving actions are stored in classes in code lib only. Code Lib would be used with WCF, wcf is used to share the classes only and classes have the data. WCF is hosted as a windows service on server used by NET.TCP

View 2 Replies

Change Connection String At Runtime?

Dec 2, 2009

I'm writing a windows form application using vs2008. I need to connect to different SQL server express database files during runtime. There is a "how to do" video showing a technique for this

[Code]...

and then in the Form1_load sub and before calling the data adapter to fill data, insert codes below:

Dim strConnectingSting = NewConnectionString
My.Settings.RunTimeConnectionString = strConnectingSting

The method works but only for the first database. I found once adapter.fill is called and the connection to a database is established, the connection can't be changed.To do what I want, I have to create a startup project to call my main project. When I want to change connection, close the main project and start again.

View 7 Replies

Change The Connection String At Runtime

Dec 19, 2011

I have a different thread on this, but I bumped it and I think it's been forgotten about. This is what I have:

[Code]....

View 5 Replies

Runtime Change On Connection String?

Apr 30, 2010

I have read through some other post and haven't been able to find an exact answer that I am looking for. I have a connection string saved in my.settings that I am using. My database is residing on a server. Now I am going to have to install this application at more then one area and they will have the database on their server. What I am wanting to do is for the application when it is loading to search the network to find the database and return the connection string without the user having to do anything. I know with a web application you can search the machine you are on for the connection string without knowing its location but was hoping there was some feature like that to search the network to find it.

View 6 Replies

Change Connection String At Runtime For Strongly Typed DataSet?

Jun 28, 2010

I need to be able to change the connection string of a strongly typed dataset at runtime. I have gone into the settings.vb page and written this code:

Namespace
My
'This class allows you to handle specific events on the settings class:
' The SettingChanging event is raised before a setting's value is changed.
' The PropertyChanged event is raised after a setting's value is changed.
' The SettingsLoaded event is raised after the setting values are loaded.
' The SettingsSaving event is raised before the setting values are saved.
[Code] .....

The way the code is suppose to work is that when a user logs in, the application gets the user's site ID (gvUserSite), then uses that to set the connection string. But when I log on with a SiteID of "21" it always uses the Case Else value. Also when I set breakpoints in settings.vb the application never stops on the breakpoints I set during runtime. As if the breakpoints were never set. Also if I put any code in the "MySettings_SettingChanging" in settings.vb I get a runtime error
"The debugger cannot continue running the process. Process was terminated.

View 10 Replies

Application Setting - Switch Main Server And Backup Connection String With Combobox

Mar 5, 2011

I have a little problem with application setting in VB.net 2008. I want to switch main server and backup server connection string with combobox. [Code] It did change the Application Setting connection string in the main form when combobox1 was changed. But the problem comes, when child form was called. On the child form there is DataGridView with Dataset using application connection string. Even the Backupserver was selected on the main form, child form dataset connection string doesn't change. I don't know how to pass the current connection string to child form dataset although it is set to use application setting.

View 6 Replies

Change LINQ To SQL Connection String While Running The Application?

Jun 11, 2012

I have a VB.NET application that used LINQ To SQL. Right now, I am using a single server and it is working properly. My problem right now is that my application will be used in another branch and with another server. I have to make the application able to change the connection string according to their server IP

View 1 Replies

Prevent The Class Library's Files From Being Opened During Main Project's Debug Mode?

Jan 24, 2009

I made a Class Library project that contains the main classes that my Main Project needs because I don't want to main classes when I distribute my project. I've successfully called and used it in my Main Project. But when I started debugging and stepping through my code which involves calling and using the class I wrote in my Class Library, I noticed that the class' file in my Class Library opens up during debug mode.

how can I prevent the Class Library's files from being opened during my Main Project's debug mode?

View 1 Replies

Change SQL Connection In Runtime?

Jul 18, 2011

I'm writing a Windows form application. I created a SQL database called myDB.mdf. The database/form connection was created using the wizard provided by VS2008. The connection string, table adapter, dataset, etc were all generated automatically. In runtime, I copied the database to several folders and I want to the application to connect to them one by one and do some data manipulation.

Here below are the relevant code I'm using:

Namespace My
Partial Friend NotInheritable Class MySettings
Public WriteOnly Property RunTimeConnectionString() As String

[Code].....

View 4 Replies

Change Class Library's Settings From An Another Program?

Apr 8, 2009

I want to change my class library's settings from an another program. For this, I've made a Public property in my class library. It worked right. But this is not my question. I wonder this is a right method? Can I access a class library's settings (My Namespace) from other project directly?

[Code]...

View 4 Replies

Change Default Printer In A Class Library?

Apr 22, 2012

If this were a Windows forms project I have used the System.Drawing.Printing namespace to accomplish my goal. However, I cannot import this namespace into a Class library.Overall here is what I am trying to do:I am trying to set the default printer using this namespace on both Windows XP and Windows 7 workstations. I am using Visual Basic 2008. My ultimate goal is to create a COM dll which is accessed from an older VBA program. The COM Dll will set the default printer to a new printer. Execution will return to the VBA program and it will print a Crystal Report. When the Crystal report is finished the VBA code will use the COM Dll one last time to set the default printer back to the original default Printer.But as I mentioned I cannot import the namespace I want to use into a Class library. Can someone give me some guidance on how to either import the namespace into a Class Library or how to determine the Default printer name and to set the Default printer to a different value?

Update: I was able to add the Imports Namespace after I added a reference to the correct DLL in Project Properties. My project is targeted at the 3.5 .Net Framework. The System.Drawing.Printing DLL is not in the 3.5 framework. That DLL is in the 2.0.50727 framework. After browsing and Adding that DLL, everything is working fine.BUT this leads to a new question. How would determining the default Printer be accomplished in the 3.5 .Net framework?Secondly, am I asking for trouble having a project target the 3.5 framework AND including a 2.0.50727 component in the same project?

View 2 Replies

C# - Call .NET 4.0 WPF Class Library From 2.0 Application

Apr 8, 2011

I have an application written in .NET 4.0 that i compile into a DLL file. I want to be able to use this DLL file in a Windows Forms .NET 2.0 application. I don't need the application to really interact much, except just passing a couple string values to the 4.0 DLL. The DLL is pretty much a bunch of Windows which i converted to UserControls and i just need to be able to reference them to display the UserControls from the 2.0 application without having to use a different exe and having to package them separately.

What is the best way to do this? Because when i try to add the reference to the DLL to the 2.0 application, it gives me and error saying the DLL is built in a newer version of .NET so i can't do it that way. Is this where a COM object would come in?

View 2 Replies

Class Library Vs. Windows Application?

Sep 28, 2010

Here is code in a form that is called from the "main" form:Imports

System.Data.SqlClient
Imports
ClassObjects
Imports

[Code]...

frmOdyssey is the main form, from which frmSearch is called. After the above processing, I want to go BACK to frmOdyssey to process the FilFilterGrid sub on the Grid defined on frm Odyssey. I will be assigning a new DataSource for the Grid, which will be "selected down" by the strFilter. The above code works with no issue whatsoever in "Windows Application" mode. However, if I switch to "Class Library" mode, I get
an error on the last line of the last Sub, telling me "Reference to a non-shared member requires an object reference". If I uncomment the "Dim f As New frmOdyssey" line, and change the "frmOdyssey" to "f" on the next line, the error goes away, but then the process doesn't work, because the "select down" does not happen. I don't know why, except that "logically" I don't want a "new version" of the frmOdyssey. I want to update the existing form.

View 8 Replies

VS 2005 - How To Hide URL String In Class Library

Jun 2, 2010

I am going to write a long code in the class library to make the source code shorter for my project. And I willing to store the url strings in the class library, but I do not know how to keep them to be more visible from people who open the dll by using with hex editor. I would like to know in which method that I should use to protected the url strings in the class library and set them more visible so no one would know what url strings that I would store in the class library if people using hex editor?

View 20 Replies

Accesing Variable Application From Class Library

Nov 5, 2010

I'm trying to acces an application variable from my class library

i.e : my varaible contain the connection string initailized in application start method

Application("ConnectionString") = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

View 3 Replies

Class Library Getting Settings From Own App.config NOT The Application's?

Jun 2, 2009

I'm having trouble with my application settings and I'm wondering if anyone else has seen this.

I have a Librabry with a connection string. In the project for the library it has its own app.config:

<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="OBInfrastructure.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>

[Code]...

View 1 Replies

Asp.net - Rewrite Webconfig Connection String At Runtime?

Mar 3, 2010

How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and Password.Is it Possible to read from these textbox?

View 1 Replies

Changing Connection String At Runtime Mode?

Mar 30, 2009

I have specified my connectionstring in My.Settings

But when I want to change it at runtime I get the error: Property connectionstring is read only.

Is it possible to change the connectionstring at runtime???

I used the following code:

[Code].....

View 1 Replies

Adding A Startup Form To A Class Library Application?

Mar 25, 2012

I have a project that was created as a class library application. It does not have any start up forms. How do I add and show a start up form to this project? Where does this application start since there is no Main Sub that I can find. I am using Visual Studio 2008 express.

View 2 Replies

Create An Application Without Distributing A Referenced Class Library

Mar 1, 2011

I am using VB .NET 2003. I have created a user defined Class Library and created a reference to it in my application. Is there a way I can compile the application so that the Class Library DLL is embedded into the application? I would really like to be able to distribute the application without having to distribute the DLL as a second a file.

In other words, I made a New Class Library lets say called TEST. I developed a new class within this library called MYCLASS. I built the Library TEST and created TEST.DLL. I then made a new visual basic project called APP1. I added a reference to TEST.DLL. I now can use TEST.MYCLASS within my APP1 project. The application APP1.EXE will run in the test environment, but if I move it to the runtime environment it will give me an error "File or assembly name TEST or one of its dependencies was not found". To correct this error I can place TEST.DLL in the directory where APP1.EXE resides. I would prefer not to have to put TEST.DLL in the directory. Can I easily compile it into APP1?

View 15 Replies

Strongly Typed DataSet Connection String At Runtime?

Oct 6, 2008

I'm sorry but Microsoft did not think about this very well. I have used the dataset wizard to connect to my sql server and the connection string was placed in the app.config file. The only problem with this is that you can not write to it nor change string at runtime. So I need a way for each one of my users to specify their connection either during installation or after installation. I would appreciate any help in this matter.

View 14 Replies

Changing A Connection String At Runtime For A Tableadapter That Was Created Using The Wizard?

Jun 21, 2010

I've created two forms of which two separate datasets/tableadapters were created by adding a datasource and dragging and dropping the fields onto my form.I was testing the program using a db that was located on my local drive. Well after publishing the app to the users machines, I noticed that the binded information was still being pulled from my local machine and not the database that the user is working off of.I've set the connection modifier properties for both tableadapters to Public, and I have written the following attempting to change the connection strings:

Private Sub btnSaveSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSettings.Click
Dim pap As New frmPap
My.Settings.dbLocation = txtSettings.Text

[code]....

View 9 Replies

IDE :: Excluding Forms To Convert A Window Forms Application To Class Library Application

Jan 16, 2012

I am not able to find the Exclude Command in VB 2010 Express. I have no idea which version of Visual Studio it is working with. I've got one 217MB VB 2010 Express file and many 2008 VB Express files with one of them measuring 31 MB. There many other SQL files and .Net Files.

View 4 Replies

VS 2010 How To Change Conn String Runtime

Dec 18, 2010

change (MS SQL) connection string (to dataset) on the start of program..

View 8 Replies

VB2010 Class Library: Create A Static Library Instead Of DLL?

Jun 21, 2011

I have a Visual Basic Class Library project. It generates a DLL. Is there a method to generate a static .LIB to which I can do a static link?Alternatively, can I do a static link against a DLL?

View 6 Replies

How To Store And Retrieve Connection String From Class

Apr 7, 2011

In my application I have many different forms each use 3 different database. And right now I am placing the connection string in each form but when it is need to change I have to change in every form. Now what I want to store all connection string in a vb class and call them in every form. So that if I need to change I can do in that class. I have stored my connection string in database so even I don't want to connect to database again and again. I have some idea in which maybe a public class is used and some how I will call it on other forms.

View 2 Replies

Change Connection String In LINQ-SQL?

Jun 17, 2010

I have developed a windows form application using VB.Net with data access layer using LINQ-SQL. I want to allow the database to be configured from the application. I have created a form for input and save the input details in an XML file.

I need to know how to configure the LINQ to start using the new configured database on startup. I have read in one of the threads here about dynamic allocating the connection string with the following solution to include in every file where the data context is instantiated. [code]...

View 1 Replies

Change The Connection String To A Different Database ?

Apr 5, 2009

Is it possible change the connection string to a different database when the user changes the database they are using .i have a working program atm but i want to be able to change the connection with out having to change the code. the databases contain information from different years but all have the same tables queries etc.

View 2 Replies

DB/Reporting :: Change A Connection String?

Jul 23, 2008

I have created a very simple Visual Studio .net 2002 VB# program. It consists of form1 containing a DataGrid bound to an Access 2007 Database using OleDbConnection1, OleDbDataAdapter1 and DataSet11.The location address of the Database will change based on the user so, I need to make the connection string variable. Problem is inserting the following string variable "source=" & strFileLocation & ";" creates a fatal error

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved