Same connection even though the ODBC data source has changed - c#

I have a .Net service that has a list of strings containing ODBC connections and I use these in a loop to check multiple databases for tasks to process (eg. polling).
However if i change where an ODBC connection points to..by changing its default database for some reason, even though i'm only storing the string name of the ODBC connection it doesn't pick up the change until i restart the application.
Is .net somehow caching all the odbc connections on startup??
How can i work around this?
Cheers.

Check if the Connection Pooling is enabled for the ODBC driver you are using at the ODBC Data Sources control panel window (this is not a .NET issue). A successful connection will stay in the pool without refreshing its new connection properties.

If your settings are stored in the app.config, here is a question that might help:
Is switching app.config at runtime possible?

Related

Visual FoxPro data in .NET

We are in the process of migrating an old VFP application into a .NET WPF application with SQL server.
During the process we still need to read/write to the DBF files to keep our business working properly.
To do this, we use the standard OLEDB adapter that is available. However, our sysadmin is asking if we have an alternative way to access the DBF files.
Having each user connect to the files is not the best option from a network/security perspective. Specially when connecting from home through a VPN.
I've already tried to move the connection to a single server by exposing the data through an API. But that was slowing down the application too much. In some situations we synchronise the data through background jobs (Hangfire implementation). But this can be time consuming to implement.
Has anybody used any other techniques to do something similar while migrating a VFP application?
OLEDB is still the best option. Within the application, you could impersonate a specific user that has access to files.
Also Sybase Advantage Server can connect and work with VFP data files. Local mode is (was) for free and server mode paid. You might try checking that too.
Locate data on single PC as server. Access via RDP - kludges available to support multiple connections. Increase security if needed by connecting over VPN - then RDP.

SQLServer AlwaysOn and .net SqlConnection reset

In our enviroment we use SQLServer Always on cluster with two servers.
One of them is for write, second for reading. In application services SqlConnection opens and closes every second for short query execution. But after switching or turning off one of the servers in Always On cluster I began get an exceptions from my application services.
This tells that it can not insert any data in read only database. I suppose that main reason for this is connection pool inside SqlConnection implementation.
So the question is how to reset that connection pool manually. Or if there another kind of problem - let me know what do you think about this behavior.
You need to set MultiSubnetFailover = True in connection string and implement retry logic:
If a SqlClient application is connected to an AlwaysOn database that
fails over, the original connection is broken and the application must
open a new connection to continue work after the failover.
SqlClient Support for High Availability, Disaster Recovery
Also:
Setting MultiSubnetFailover to true isn't required with .NET Framework
4.6.1 or later versions.

App.config.exe connectionstring tricks

I'm trying to develop multi client in C# with SQL Server 2008 data Base, after made setup file and install it to client I cannot access DataBase in server. I used LINQ to Connect DataBase and have App.config xml file in my project which ConnectionString Declare there and I after installing the application I change that XML file's ConnectionString to right way(Server name and sql instance name), but this change doesn't have any impact, whats the problem maybe have my solution?
If any one has experience about developing multi client application share with me.
and also How can I change scope in project properties from Application to User, It's may be solve my problem
Thank you
In this project we use LINQ to connect Database to server, and we can get right Database address dynamically from User Interface and use it in constructor of DataContext:
public DataClasses1DataContext(string connection)
And then it don't care in embed connection string, its use only that connectionString in their constructor.
If the error mentions "provider: Named Pipes Provider", then your application is trying to connect via named pipes to your SQL Server, is that what you want? You can prefix the server name with tcp: to force TCP/IP usage instead i.e. Server=tcp:ServerName if you wish to use TCP.
If you want to use named pipes it is possible that support for it is turned off on the server, I believe it is disabled by default. You would need to enable it via the SQL Server configuration manager program on the server, in the network configuration, protocols section.
hmmm, hard to say without the connection strings or error message, but some ideas....
When you change the app.config, restart app to verify changes.
Try pinging the server from the where the app is being installed.
Check firewall settings. shared network.
Use your new connection string on your development machine on the same network if local.

Provider field in connection string oledb

Hey guys I'm new to C# and I'm a little confused on the fields that need to be provided in the connection string while using oledb to connect to my sql server 2008 database, particularly one of them.
The "Provider" field is really giving me problems, partially because I'm not really sure what it does. I have tried two different Provider strings and they both come back with the same error:
The "System.Data.SqlClient provider is not registered on the local machine
Or
The "Microsoft.Jet.OLEDB.4.0" provider is not registered on the local machine
Can someone tell me what this means? Also, my task requires me to not use any addition installations, is there a provider that is default?
Thanks
The Microsoft Jet Engine is the database engine used in Microsoft Access. The error simply means that the required Access version is not installed and thus, your application cannot open the OLEDB driver.
Generally, you should probably just use the System.Data.SqlClient.SqlConnection class instead of the System.Data.OleDb.OleDbConnection class to connect to your SQL Server 2008 database. The connection string should be much simpler.

Managing windows application's DB connection

There's no particular problem, I just wanted to ask whther I'm doing it right or wrong.
I have connection string stored in Settings.Default.ServerConnection property on which rely all DB-related objects. I also use auto-generated TableAdapters for server-side stored procedures (SQL Server 2008 R2 Express) with Connection property set to use mentioned connection property. There is a settings form where I can setup a connection to any server on the local network (using SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources()) and store it in app's settings.
So I was wondering if it's the right approach of doing such thing or not because when app is executed for the first time it's still able to connect to SQL server without even configuring the connection (Data Source set to (local) by default).
If I'm understanding the question... :-)
Your app is able to connect to local because that is the how its bound in its current environment (say it was a remote IP, it wouldn't work).
Storing connection string information in the config file (e.g. app.config) is a great idea, because it can be changed on the fly without a rebuild.

Categories

Resources