472,338 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 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 3773
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...
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...
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...
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....
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...
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...
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...
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.