本文介绍了如何获取本地系统中安装的SQL Express的正确登录地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的专家,

我已经在本地系统中安装了SQL Server Express Edition.我想以编程方式(C#)了解登录实例的正确实例(服务器名称).

我写了一个小应用程序来从注册表中读取.


Dear Experts,

I''ve SQL Server express edition installed in my local system. I want to know the corrrect instance (server name) programetically(C#) forlogin purpouse.

i wrote a small application to read from the registry.


RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");            String[] instances = (String[])rk.GetValue("InstalledInstances");            if (instances.Length > 0)            {                foreach (String element in instances)                {                    MessageBox.Show(element);                }            }



但是我的问题是我必须输入上面的键SQLEXPRESS和SQLEXPRESSMYLOG.所以我不知道什么是正确的登录地址.

请告诉我,我该怎么办?

谢谢大家.



But my problem is that I''ve to entry in above key SQLEXPRESS and SQLEXPRESSMYLOG. So I''m not able to know what is the correct login address.

Please tell me, how can i do it?

Thank you all in advance.

推荐答案

string[] InstanceNames = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL").GetValueNames();

string ServerName = string.Empty;
foreach (string str in InstanceNames)
{
    ServerName = string.Empty;
    ServerName = string.Concat(System.Environment.MachineName, "\\", str);
    MessageBox.Show(LoginName);
}


这篇关于如何获取本地系统中安装的SQL Express的正确登录地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:55