Generic failure, wmi

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

Im trying to add a A record to a domain name in MS DNS with C#, it's done
from a webpage with this code:

ManagementClass rr = new ManagementClass(@"root\MicrosoftDNS",
"MicrosoftDNS_ResourceRecord",
new ObjectGetOptions(null,new TimeSpan(100), true));
string _ResellerDomainName = "mydomain.net.";
object rrText = "web IN A 123.123.123.123";

rr.InvokeMethod("CreateInstanceFromTextRepresentation", new
object[] { ".", _ResellerDomainName, rrText});

The record is added to the domain but I get this error even thou it worked:

System.Management.ManagementException: Generic failure at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus
errorCode) at System.Management.ManagementObject.InvokeMethod(String
methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at System.Management.ManagementObject.InvokeMethod(String methodName,
Object[] args) at WebDNS.DNSClass.AddRecord() in c:\documents and
settings\anders\vswebcache\webadmin\dnsclass.cs:line 30

All permissions must be correct thou the domain is added.
Have seen other with this error but no solutions!
Line 30 is the InvokeMethod
What is causing the error and what can I do to solve it?

Regards
Anders Aleborg
 
Hi Anders,

Sorry for the late response.

For this issue, I think you are running the code in a ASP.NET web
application, right?

Could you please create a console application and run the code to see
whether it has any problem? If there is no exception in console
application, we may isolate the issue to the identity that asp.net web
application running on.

Besides, please also test the following sample code: (it is for console
app, you can change Console.WriteLine to response.write for asp.net app)

ManagementClass dnsRRClass = new
ManagementClass(@"\\ServerNameHere\root\MicrosoftDNS",
"MicrosoftDNS_ResourceRecord", null);
ManagementBaseObject inParams =
dnsRRClass.GetMethodParameters("CreateInstanceFromTextRepresentation");
inParams["DnsServerName"] = sServer;
inParams["ContainerName"] = sDomainName;
inParams["TextRepresentation"] = sTextRepresentation;
ManagementBaseObject outParams =
dnsRRClass.InvokeMethod("CreateInstanceFromTextRepresentation", inParams,
null);
Console.WriteLine("Executing the method returns {0}",
outParams["ReturnValue"]);

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi!

Got this error from the consol:
D:\>wmitest

Unhandled Exception: System.Management.ManagementException: Generic failure
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStat
us errorCode)
at System.Management.ManagementObject.InvokeMethod(String methodName,
Managem
entBaseObject inParameters, InvokeMethodOptions options)
at WMITest.Class1.Main(String[] args)

The record was added and is working in the DNS but I still get the error :/

Regards
Anders Aleborg
 
Hi Anders,

Then that seems not related to ASP.NET security.

Have you tested the code that I pasted before? What is the return value
from the last line? Thanks very much for your update. :)

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
By the way, if it still returns error, could you please paste you .cs file
here? I will test it on my side and contact our supporting team to look
into it.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
It givs the error I posted!

using System;
using System.Management;

namespace WMITest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ManagementClass dnsRRClass = new
ManagementClass(@"\\"+ System.Environment.MachineName
+@"\root\MicrosoftDNS",
"MicrosoftDNS_ResourceRecord", null);

ManagementBaseObject inParams =
dnsRRClass.GetMethodParameters("CreateInstanceFromTextRepresentation");

inParams["DnsServerName"] = ".";
inParams["ContainerName"] = "domain.net";
inParams["TextRepresentation"] = "test IN A 123.123.123.123";

ManagementBaseObject outParams =
dnsRRClass.InvokeMethod("CreateInstanceFromTextRepresentation", inParams,
null);

Console.WriteLine("Executing the method returns {0}",
outParams["ReturnValue"]);

}
}
}
 
Have tried with this code as well, the record is created but it gives me a
generic failure message.

public string AddRecord(string domainname, string host, string
recordtype,int MXPrio, string target)
{
try
{
ManagementClass dnsRRClass = new ManagementClass(@"\\"+
System.Environment.MachineName +@"\root\MicrosoftDNS",
"MicrosoftDNS_"+recordtype+"Type", null);
ManagementBaseObject inParams =
dnsRRClass.GetMethodParameters("CreateInstanceFromPropertyData");

inParams["DnsServerName"] = ".";
inParams["ContainerName"] = domainname;
inParams["OwnerName"] = host;

if(recordtype=="A")
inParams["IPAddress"] = target;
if(recordtype=="CNAME")
inParams["PrimaryName"] = target;
if(recordtype=="NS")
inParams["NSHost"] = target;
if(recordtype=="MX")
{
inParams["Preference"] = MXPrio;
inParams["MailExchange"] = target;
}

dnsRRClass.InvokeMethod("CreateInstanceFromPropertyData", inParams,
null);
return "ok";
}
catch(Exception ex)
{
return ex.ToString()+"<br><br>"+ex.StackTrace.ToString();
}
}
 
Hi Anders,

Thanks very much for the detailed update.

I am contacting our support team on it and will reply here as soon as
possible. If you have any more concerns on it, please feel free to post
here.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Yes, I have one more problem, when I try to delete a zone or a record it
takes time, about 40-60 seconds to delete a zone!!! And the CPU goes up to
100% on the server. It can't be normal.

The code:
Delete("MicrosoftDNS_Zone", "ContainerName", "domain.com")

protected bool Delete(string sTableName, string sFieldName, string
sFieldValue)
{
try
{
string sQuery = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'",
sTableName, sFieldName, sFieldValue);
ManagementScope m_oScope;

m_oScope = new ManagementScope(new ManagementPath(@"\\" +
System.Environment.MachineName + @"\root\MicrosoftDNS"));
m_oScope.Connect();

ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(m_oScope, new ObjectQuery(sQuery));
ManagementObjectCollection oCollection = oSearcher.Get();

foreach (ManagementObject oObject in oCollection)
{
oObject.Delete();
}
return true;
}
catch
{
return false;
}
}

Regards
Anders Aleborg
 
Hi Anders,

Thanks for the quick response. I have contacted our WMI support team and we
will get back here as soon as possible. It may need some more time, but
please rest assured that we will do the best to be of assistance.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Anders,

Here I help post the reply from our supporting team:

------------
Anders,

I had to do some testing but it seems that the method is expecting a little
different parameters.

In your sample code you are passing in the following as your
TextRepresentation:
"web IN A 123.123.123.123"

I have found that the DNS provider is looking for the following format:
"web.mydomain.net IN A 123.123.123.123"

As for the zone issue:
I have not seen this issue on my test servers. Is the zone you are deleting
empty or is it full of records? Are you running the C# code directly on the
server or are you running it on a separate machine and connecting remotely?
Have you also tried doing the same action via script to see if the problem
is .Net or the DNS WMI provider?

Mike Dutra
Microsoft Developer Support WSH/WMI/Cluster Dev

Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.
-------------------------

Please feel free to reply here if you have any more concerns. Thanks very
much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi!

That did the trick with the TextRepresentation, thanks!

The zone has 5-8 records but the error occurs even when I try to delete a
secondary zone.
The C#-code is on the server and I have only tried to do it from .NET

Regards
Anders Aleborg
 
Hi Anders,

I will contact Mike on it again. Thanks very much for your follow up.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Anders,

Can you run the following script on the server (editing it accordingly) and
see if it too takes a long time to delete a zone?

Dim oLocator, oService
Dim objDNS

Set oLocator = CreateObject("WbemScripting.SWbemLocator")
Set oService = oLocator.ConnectServer("", "root\MicrosoftDNS")

Set objServer = oService.Get("MicrosoftDNS_Server.name="".""")
Set objDNS =
oService.Get("MicrosoftDNS_Zone.ContainerName=""MikeZone"",DnsServerName="""
& objServer.Name & """,Name=""MikeZone""")
objDns.Delete_

Mike Dutra
Microsoft Developer Support WSH/WMI/Cluster Dev

Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.
--------------------
 
Hi Mike!

That went smooth...
Then the question is, how do I delete a zone from C# so that it goes as
smoothly as the VBS file?

Regards
Anders Aleborg
 
What version of the .Net framework do you have on the machine? I have heard
of some people having delays in the launching of .Net apps with some
versions of the framework. I am using .Net 1.1 SP1.

Mike Dutra
Microsoft Developer Support WSH/WMI/Cluster Dev

Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.
--------------------
 
Hi!

I'm using .NET 1.1 SP1 as well(the latest)
The delay is only the first time the script is accessed after a build, this
error only applies to deleting of zones and SOA records(almost the same code).
Or to be more exact it only applies to ManagementObjectSearcher

This code:
string sQuery = "SELECT * FROM MicrosoftDNS_Zone WHERE ContainerName =
'domain.com' AND Name='domain.com'";
ManagementScope m_oScope;

m_oScope = new ManagementScope(new ManagementPath(@"\\" +
System.Environment.MachineName + @"\root\MicrosoftDNS"));
m_oScope.Connect();

ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(m_oScope,
new ObjectQuery(sQuery));
ManagementObjectCollection oCollection = oSearcher.Get();

foreach (ManagementObject oObject in oCollection)
{
oObject.Delete();
break;
}

takes 20-30 seconds with or without the oObject.Delete()
Has also tried to add the DnsServerName in the query.

Regards
Anders Aleborg
 
Anders,

I do not se the same delay you are speaking of but I do see approximately a
6 - 8 second delay for the .Net framework to launch the first time it is
run. You keep mentioning an error. Do you also see an error? If you comment
out the searcher object how long does the first run take? Based on the fact
that script is fast and .Net is slow but only the first time I suspect this
is just the delay of the framework starting. I would not have expected it
to be quite that slow though.

Mike Dutra
Microsoft Developer Support WSH/WMI/Cluster Dev

Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.
--------------------
 
Hi!

Well it's not an error, just me expressing my self wrong. By error I mean
it's slow and it isn't caused by .NET starting up, this is inside a .NET
application and .NET has been "started" for a while.
I have built a webinterface for MS DNS on a Windows 2003 Server Web
Edition(also tried it on 2 other servers with Standard edition), so I log in
to my interface(.NET all through), first I add a domain, no problems,then I
add and delete resource records, no problem,and after that I delete a domain,
no problem but it takes about 40 seconds.
This seems to be an issue with the searcher object and C#.

Regards
Anders Aleborg
Aleborg Solutions
 
Back
Top