473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#-WEB: ManagementObject Delete DNS TXT records not working

9
I can Add and Delete (A, CName, MX and TXT) Dns records on the Dns Server using C# code. The problem I am having is if someone manaully creates a TXT record on the Dns Server, I cannot delete that particular record using the same C# code. Here is what I am using to delete the records:
Expand|Select|Wrap|Line Numbers
  1. public void DeleteRecord(string domain, string recordName, string recordType, string recordData)
  2.         {
  3.             try
  4.             {
  5.                 this.ConnectToDNS(dnsServerList[x].Server, dnsServerList [x].UserName, dnsServerList[x].Pass);
  6.  
  7.                 // Find Record to Delete
  8.                 string wql = "";
  9.                 wql = "SELECT *";
  10.                 wql += " FROM MicrosoftDNS_TXTType";
  11.                 wql += " WHERE ContainerName = '" + domain + "'";
  12.                 wql += " AND recordData = '" + recordData + "'";
  13.                 wql += " AND OwnerName = '" + ownerName + "'";
  14.                 ObjectQuery q = new ObjectQuery(wql);
  15.                 ManagementObjectSearcher s = new ManagementObjectSearcher(this.Session, q);
  16.                 ManagementObjectCollection col = s.Get();
  17.                 int total = col.Count;
  18.                 foreach (ManagementObject o in col)
  19.                 {
  20.                     // Record to Delete was found
  21.                     o.Delete();
  22.                     o.Dispose();
  23.                 }
  24.             }
  25.             catch (Exception)
  26.             {
  27.                 throw;
  28.             }
  29.         }
  30.  
When the C# code tries to Delete the manually created TXT record 'o.Delete()' does not produce any errors it just doesn't do anything.

Here is a TXT record created manually on the Dns Server:

" TXT ( "v=spf1 ip4:0.0.0.0 ip4:0.0.0.0 ?all" )"

Here is a TXT record created by C# code:

" TXT ( "v=spf1 ip4:0.0.0.0 ip4:0.0.0.0 ?all"
"" )"

The interesting thing is, if I edit the TXT record manually on the Dns Server and move the cursor to the end of the text in the TextBox and hit the 'Enter' key on my keyboard then save the change, my C# code can then delete that TXT record. When you type 'Enter' after the text in the textbox on a Dns Server it formats the record to match my C# code.

Anyway I just need to find out why I can't delete a TXT record that was manually created on a Dns Server when the person entering the text does not actually hit the 'Enter' key. I would appreciate any help you could provide. Thanks in adavance.
Nov 9 '07 #1
5 3893
Plater
7,872 Expert 4TB
Does that record work as a valid record without that extra cariage return?
does it ONLY apply to TXT type records? (Which BTW, I've yet to figure out how to use)
Nov 9 '07 #2
sh26
9
Does that record work as a valid record without that extra cariage return?
does it ONLY apply to TXT type records? (Which BTW, I've yet to figure out how to use)
Yes both records are valid formats and yes it only applies to TXT type records. It is almost like the method used to create a TXT manually on a Dns Server does not add the cariage return where the method in C# adds it for you. Then the Delete method in C# requires it to be there before it can do anything with it.
Nov 9 '07 #3
sh26
9
Still trying to figure this out... If anyone has an idea let me know thanks.
Nov 13 '07 #4
Plater
7,872 Expert 4TB
Is there a non-code way to delete these records? That you could like invoke instead of the .net method? I don't like suggesting an API call over a framework call, but you might be able to find something?
Nov 13 '07 #5
sh26
9
Is there a non-code way to delete these records? That you could like invoke instead of the .net method? I don't like suggesting an API call over a framework call, but you might be able to find something?
I think I could find a way to delete them manually via API, etc. but since the .net code is not returning any errors I would not have a way to trigger the API.
Nov 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
2
by: Robin | last post by:
I have a main table that I need to delete records that arn't referenced in another. Query says I cannot delete. If I remove the reference query all deletes ok. Hope there is a way around this ?...
1
by: davea | last post by:
Hi I have a command button that when clicked deletes certain records from a subform based on an application number being equal. It deletes all records with the same applciation number as...
6
by: satish mullapudi | last post by:
Hi All, I am getting strange situation. These r the steps I have followed: 1. Created an EMPLOYEE table with around 14 fields & 688038 records. (so a large table indeed). 2. Tried to delete all...
4
by: felicia | last post by:
Hi All, Below is my code to delete records: adodcAllEntries.Recordset.MoveFirst Do While (adodcAllEntries.Recordset.EOF = False) If adodcAllEntries.Recordset.Fields(0) = selected_id Then...
2
by: mady1380 | last post by:
Hi All I am new with Windows form. i am working on c#.net 2003. i have no idea how am i suppose to Edit, AddNew or Delete Record in DataGrid. I am passing a Dataset to my Grid. I want to...
2
by: =?Utf-8?B?SWJyYWhpbS4=?= | last post by:
Hello, I have a client c# application from which I want to Add/Edit/Delete & list records by connecting to Web Service. HOw can I write classes & methods in Web service projet that will : ...
9
by: MEGDZIA | last post by:
Could you please advise whether it is possible to delete records in suborm. When I highlight whole record it won't let me do it. I've chcecked all properties and it should allow to delete...
4
by: jessiK | last post by:
Pls help! I'm new to PHP and MySQL and I'm having a problem when working with my database (I am using IIS6). When using PHP I can connect to the database without any problems, I can even add new...
6
by: kstevens | last post by:
I have tables setup with a main table for information and a subtable that records the "multiple" records for the main record. I have written a query to go in and find Null or "" values to delete...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.