Friday, June 27, 2008

VS 2005: Connection String Modifications in Class Libraries

Scenario:

An excellent practice in coding is to centralize and conseal data access code so that you do not have to reset configuration or in our case the "connection string" all over the places. You've probably experiencd that if you created a DataSet in the same project as all your main forms, connection string is in the Application's Settings file. And upon the form inialization, you can just change the connection string property then you are all set for the rest of the code.

What happens though if you placed the DataSet in a separate library. In this case you don't see the connection string any more in your Application's config file or Settings.

My Solution:

There are many different ways of doing this, from creating a factory class to overriding some config class objects that returns the correct (dynamically changed) connection string.

My solution is quite minimum compared to those but it does work and it does not require a lot of lines of code.

If you have created a Class Library on its own project then there is a namespace that is assigned to that project. If you create a DataSet in this project then it will create a local settings directory.

I usually have a database locally and so when I am developing I set my SQL hostname by default to (local) and when I go in production I just need to repoint the host name. The following code then will replace that with another hostname.

The property setting values are singletons (at least they seem to be) so if you run this once early on in your program execution, all the TableAdapters that use the connection string will take the new value from it.


namespace MyClassLib{
public class DBConnections
{
static public void SetDBHost(string hostName)
{
string cs =
Properties.Settings.Default.ConnectionString1;

cs = cs.Replace("(local)", hostName);
Properties.Settings.Default["ConnectionString"] = s; }
}
}

VS 2005: DataSet Designer Gives Unable To Find Connection Error

Symptom/ Situation:

You are using Microsoft Visual Studio 2005, and you have moved a DataSet (.xsd file set) from one location to another in your project on your Visual Studio 2005 and you get this kind of an error any time you want to add or modify a query in the Table Adapter, and you cannot add, delete, edit or modify the query that was previously defined.

Unable to find connection 'db1ConnectionString (MySettings)1' for object 'MySettings'. The connection string could not be found in application settings, or the data provider associated with the connection string could not be loaded. "

Possible Fix:

I had this issue and found out how to fix this in my case. Your case may vary.
  • In the DataSet Designer mode click over the heading of the TableAdapter part and reveal its property.
  • In the properties panel (usually on your right) you will see +Connection.
  • Press the + icon
  • Click the Value part of the connection and a pull-down menu will appear. (Re)select the proper connection string
  • Now you should be able to modify the queries

Wednesday, June 25, 2008

Mac Tiger Does Not Autheticate When Connecting To WIndows 2003

Symptom:

When trying to access a file share (SMB share) from a Mac OS 10.4 (Tiger) to Windows 2003 Server which is in a Windows domain, you get a login screen, but it always fails on authentication.

Cause:

The "Microsoft network server: Digitally sign communications (always)" is Enabled in the Security Options of Local Policies of Security Settings in the Default Domain Controller Security Settings.

Fix:

This applies to Tiger which is running an older version of Samba software. A new version of it will not have this issue, and I have not checked that with Leopard.

Note that this may violate your general local security policy and may expose your windows server with additional security issues.
  1. From the Start Menu, open Administrative Tools
  2. Select Domain Controller Security Policy
  3. In the Default Domain Controller Security Settings applet navigate through Security Settings, Local Policies, Security Options
  4. Scroll down the list and find "Microsoft network server: Digitally sign communications (always)
  5. Disable it.
  6. From the command line tool type in "gpupdate" to load the change into the OS.

Time Took To Research and Fix This

About year and half.

Wednesday, June 11, 2008

ATT 8525 Phone Connectivity Instable

Symptom:

I have been using ATT (Cingular, HTC) 8525 for sometime, but whenever it switches to and from 3G to GSM (EDGE) networks there have always been all sorts of problems like a call dropping, cannot connect re-establish data connections etc. It also seems to get worse from either other networks, towers or a situation where there is an GSM only tower near-by and 3G tower at a receivable distance.

Fix:

I have disabled 3G from the phone and it operates much more stable. There is a registry hack you can do to show the bandwidth selector.

To enable the bandwidth selector tab in the Phone setup page.

[\HKLM\Software\OEM\PhoneSetting\]
"ShowUMTSBandPage"=dword:00000001

And this disables it.

[\HKLM\Software\OEM\PhoneSetting\]
"ShowUMTSBandPage"=dword:00000000

There is a freeware called MobileRegistryEditor that you can install it on your desktop and you can "remotely" alter the registry keys via a USB connection.

As with any registry hack, I cannot be responsible if you screw up your phone permanently.

Tuesday, June 03, 2008

Windows DNS: nslookup works but ping does not work

Symptom:

You are hosting your own DNS on Windows Server 2003 or likewise. Occasionally (especially after rebooting the DNS server), hostmame lookup does not occur, for example, ping or http request to your local host(s) from a web browser.

Boodoo Answer:

I do not know why or what is happening with this and I don't have time to figure out really what's gogin on but what helps are two things,

From a command line, try typing in "ipconfig /flushdns"

If that does not work you can try the following;

  • Allow Dynamic updates on your Primary DNS nodes from the DNS configuration applet.
  • Create reverse lookup zones.