日期:2014-05-19  浏览次数:20818 次

请教一个数据库连接的问题!
c#   2005   sql2000

我把基本的server,uid,pwd放在注册表里,我想在一个类里调用注册表的这些信息,连接到数据库...请写详细的代码...谢谢....

------解决方案--------------------
抢个沙发~
------解决方案--------------------
using System.Data;
using System.Data.SqlClient;

...

string strConnection= "user id=sa;password=; ";
strConnection+= "initial catalog=Northwind;Server=YourSQLServer; ";
strConnection+= "Connect Timeout=30 ";

SqlConnection objConnection=new SqlConnection(strConnection);

...

objConnection.Open();
objConnection.Close();

...


------解决方案--------------------
比如:
先写:
RegistryKey rk = Registry.LocalMachine.OpenSubKey (键目录);
rk.SetValue( "uid ", "sa ");
rk.SetValue( "server ", ". ");
.......
读出来是:
RegistryKey rk = Registry.LocalMachine.OpenSubKey (键目录);
string userid = rk.GetValue( "uid ");
....
....
然后你就连就是了
键目录你可以写在配置文件里吧
------解决方案--------------------
怎么写注册表,还有怎么读信息.
------解决方案--------------------
同意 amwanfwbx(滴水的屋檐) 的