请问怎样才能利用C#自动从Windows2000的机器上获取机器内已装的ODBC数据源的内容?

jeall 2003-12-03 10:27:25
我的意图是每次获取了ODBC数据源后,能够选择某一数据源进行数据操作!
...全文
48 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2003-12-03
  • 打赏
  • 举报
回复
>>>异常详细信息: System.Security.SecurityException:
>>>不允许所请求的注册表访问权

it has nothing to do with your web.config
jeall 2003-12-03
  • 打赏
  • 举报
回复
yes! but
<allow users="*" />
is include ASPNET
saucer 2003-12-03
  • 打赏
  • 举报
回复
same thing, webservice is also running as ASPNET account
jeall 2003-12-03
  • 打赏
  • 举报
回复
我用的不是 webform 而是 C#的*.aspx webservice
saucer 2003-12-03
  • 打赏
  • 举报
回复
are you using webform? consider to change userName to "SYSTEM" in <processModel> in machine.config, or use impersonation, see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspnetimpersonation.asp


http://support.microsoft.com/default.aspx?scid=KB;en-us;306158&
jeall 2003-12-03
  • 打赏
  • 举报
回复
我添加了<allow roles="GET" users="*" />
<allow roles="POST" users="*" />
jeall 2003-12-03
  • 打赏
  • 举报
回复
我测试了一下,出现<安全性异常>
安全性异常
说明: 应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别。

异常详细信息: System.Security.SecurityException: 不允许所请求的注册表访问权。

我的authentication设置是这样的:
<authentication mode="Windows" />
<authorization>
<allow users="*" /> <!-- 允许所有用户 -->
</authorization>
</authorization>

我试图改变权限后,仍不行!希望大家能够告诉我正确的设置方式!谢谢~!
saucer 2003-12-03
  • 打赏
  • 举报
回复
someone is faster, :-)
saucer 2003-12-03
  • 打赏
  • 举报
回复
see
Reading ODBC Data Source Names in VB.NET
http://www.c-sharpcorner.com/Code/2002/Sept/ReadODBCDSNs.asp
shajie 2003-12-03
  • 打赏
  • 举报
回复
直接读注册表,每个ODBC数据源都在注册表里有响应的键值,具体位置可以去咕咕搜搜
saucer 2003-12-03
  • 打赏
  • 举报
回复
the easiest way for you to do is

change userName to "SYSTEM" in <processModel> in machine.config
jeall 2003-12-03
  • 打赏
  • 举报
回复
using Microsoft.Win32;
private void ReadODBCSNs()
{
string str;
RegistryKey rootKey;
RegistryKey subKey;
string[] dsnList;
int dsnlength;

//Load System DSNs
rootKey=Registry.LocalMachine;
str="SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources";
subKey = rootKey.OpenSubKey(str);
dsnList = subKey.GetValueNames();
dsnlength = dsnList.Length;
this.ListBox1.Items.Add("System DSNs");
this.ListBox1.Items.Add("====================");

for(int i=0;i<dsnlength;i++)
{
this.ListBox1.Items.Add(dsnList[i].ToString().Trim());
}

subKey.Close();
rootKey.Close();

//Load User DSNs
rootKey=Registry.CurrentUser;
str="SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources";
subKey = rootKey.OpenSubKey(str);
dsnList = subKey.GetValueNames();
dsnlength = dsnList.Length;

this.ListBox1.Items.Add("================");
this.ListBox1.Items.Add("User DSNs");
this.ListBox1.Items.Add("================");

for(int j=0;j<dsnlength;j++)
{
this.ListBox1.Items.Add(dsnList[j].ToString().Trim());
}

subKey.Close();
rootKey.Close();
}
同样是administrator,问什么查看User DSN 时在dsnList = subKey.GetValueNames();
时候却提示<未将对象引用设置到对象的实例> 不知道原因,而且注册表里存在用户DSN,路径也正确?????急!
jieall 2003-12-03
  • 打赏
  • 举报
回复
UP!
jeall 2003-12-03
  • 打赏
  • 举报
回复
目前状态:
1、what user the thread is executing as: TONGLN\ASPNET
2、web.config中
<system.web>
<identity impersonate="true"/>
3、计算机管理中的ASPNET隶属于administrators、debugger users

仍然出现:>>>异常详细信息: System.Security.SecurityException:
>>>不允许所请求的注册表访问权

我把web.config更改成
<system.web>
<identity impersonate="true" username=administrator password=1234/>
后系统未出错,执行结果:The central processor of this machine is:GenuineIntel
程序代码为:
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
// Create a new key under HKEY_LOCAL_MACHINE\Software as MCBInc
RegistryKey key = Registry.LocalMachine.OpenSubKey("Software", true);
// Add one more sub key
RegistryKey newkey = key.CreateSubKey("MCBInc");
// Set value of sub key
newkey.SetValue("MCBInc", "NET Developer");
// Retrieve data from other part of the registry
// find out your processor
RegistryKey pRegKey = Registry.LocalMachine;
pRegKey = pRegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
Object val = pRegKey.GetValue("VendorIdentifier");
Response.Write ("The central processor of this machine is:"+ val);
请指教!

jeall 2003-12-03
  • 打赏
  • 举报
回复
wait a moment ! I study !
jeall 2003-12-03
  • 打赏
  • 举报
回复
ye! Why did you know?

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧