1、查询sqlserver所有服务器名
using System.Data.Sql;
class Program
{
static void Main()
{
// Retrieve the enumerator instance and then the data.
SqlDataSourceEnumerator instance =
SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
// Display the contents of the table.
DisplayData(table);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
private static void DisplayData(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
}
Console.WriteLine("============================");
}
}
}
2、怎样下载SQLSERVER服务器??/
不要分开下载,一个完整的SQL软件是包含所有的插件的,当然也包含服务器,如果单独下载安装,用的时候很容易出一些很难找到的错误
3、如何实现一台SQLserver 服务器同步多台SQLserver服务器中的某一个或多个数据库
在两个SQLSERVER之间实现数据同步:
第一先来配置出版服务器
(1)选中指定[服务器]节点
(2)从[工具]下拉菜单的[复制]子菜单中选择[发布、订阅服务器和分发]命令
(3)系统弹出一个对话框点[下一步]然后看着提示一直操作到完成。
(4)当完成了出版服务器的设置以后系统会为该服务器的树形结构中添加一个复制监视器。同时也生成一个分发数据库(distribution)
第二创建出版物
(1)选中指定的服务器
(2)从[工具]菜单的[复制]子菜单中选择[创建和管理发布]命令。此时系统会弹出一个对话框
(3)选择要创建出版物的数据库,然后单击[创建发布]
(4)在[创建发布向导]的提示对话框中单击[下一步]系统就会弹出一个对话框。对话框上的内容是复制的三个类型。我们现在选第一个也就是默认的快照发布(其他两个大家可以去看看帮助)
(5)单击[下一步]系统要求指定可以订阅该发布的数据库服务器类型,SQLSERVER允许在不同的数据库如 ORACLE或ACCESS之间进行数据复制。但是在这里我们选择运行"SQL SERVER 2000"的数据库服务器
(6)单击[下一步]系统就弹出一个定义文章的对话框也就是选择要出版的表
(7)然后[下一步]直到操作完成。当完成出版物的创建后创建出版物的数据库也就变成了一个共享数据库。
第三设计订阅
(1)选中指定的订阅服务器
(2)从[工具]下拉菜单中选择[复制]子菜单的[请求订阅]
(3)按照单击[下一步]操作直到系统会提示检查SQL SERVER代理服务的运行状态,执行复制操作的前提条件是SQL SERVER代理服务必须已经启动。
(4)单击[完成]。
4、查询sqlserver所有服务器名
.net 列出局域网内所有的SQLserver服务器的名字
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Runtime.InteropServices;
namespace showSqlServer
{
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[DllImport("odbc32.dll")] private static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);
[DllImport("odbc32.dll")]
private static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);
[DllImport("odbc32.dll")]
private static extern short SQLFreeHandle(short hType, IntPtr handle);
[DllImport("odbc32.dll",CharSet=CharSet.Ansi)]
private static extern short SQLBrowseConnect(IntPtr hconn, StringBuilder inString,
short inStringLength, StringBuilder outString, short outStringLength,
out short outLengthNeeded);
private const short SQL_HANDLE_ENV = 1;
private const short SQL_HANDLE_DBC = 2;
private const int SQL_ATTR_ODBC_VERSION = 200;
private const int SQL_OV_ODBC3 = 3;
private const short SQL_SUCCESS = 0;
private const short SQL_NEED_DATA = 99;
private const short DEFAULT_RESULT_SIZE = 1024;
private System.Windows.Forms.ComboBox comboBox1;
private const string SQL_DRIVER_STR = "DRIVER=SQL SERVER";
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
public string[] GetServers()
{
string[] retval = null;
string txt = string.Empty;
IntPtr henv = IntPtr.Zero;
IntPtr hconn = IntPtr.Zero;
StringBuilder inString = new StringBuilder(SQL_DRIVER_STR);
StringBuilder outString = new StringBuilder(DEFAULT_RESULT_SIZE);
short inStringLength = (short) inString.Length;
short lenNeeded = 0;
try
{
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, henv, out henv))
{
if (SQL_SUCCESS == SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(IntPtr)SQL_OV_ODBC3,0))
{
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, henv, out hconn))
{
if (SQL_NEED_DATA == SQLBrowseConnect(hconn, inString, inStringLength, outString,
DEFAULT_RESULT_SIZE, out lenNeeded))
{
if (DEFAULT_RESULT_SIZE < lenNeeded)
{
outString.Capacity = lenNeeded;
if (SQL_NEED_DATA != SQLBrowseConnect(hconn, inString, inStringLength, outString,
lenNeeded,out lenNeeded))
{
throw new ApplicationException("Unabled to aquire SQL Servers from ODBC driver.");
}
}
txt = outString.ToString();
int start = txt.IndexOf("{") + 1;
int len = txt.IndexOf("}") - start;
if ((start > 0) && (len > 0))
{
txt = txt.Substring(start,len);
}
else
{
txt = string.Empty;
}
}
}
}
}
}
catch (Exception ex)
{
#if (DEBUG)
MessageBox.Show(ex.Message,"Acquire SQL Servier List Error");
#endif
txt = string.Empty;
}
finally
{
if (hconn != IntPtr.Zero)
{
SQLFreeHandle(SQL_HANDLE_DBC,hconn);
}
if (henv != IntPtr.Zero)
{
SQLFreeHandle(SQL_HANDLE_ENV,hconn);
}
}
if (txt.Length > 0)
{
retval = txt.Split(",".ToCharArray());
}
return retval;
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(56, 32);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 302);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.comboBox1.Items.Clear();
string[] SqlServer=this.GetServers();
if(SqlServer==null ||SqlServer.Length==0)
return;
foreach(string server in SqlServer)
{
this.comboBox1.Items.Add(server);
}
if(this.comboBox1.Items.Count>0)
this.comboBox1.SelectedIndex=0;
}
}
}
5、jdbc怎么连接sqlserver服务器下的数据库
java中使用jdbc连接sql server数据库步骤:
1.JDBC连接SQL Server的驱动安装 ,前两个是属于数据库软件,正常安装即可(注意数据库登陆不要使用windows验证)
将JDBC解压缩到任意位置,比如解压到C盘program files下面,并在安装目录里找到sqljdbc.jar文件,得到其路径开始配置环境变量
在环境变量classpath 后面追加 C:\Program Files\Microsoft SQL Server2005 JDBC Driver\sqljdbc_1.2\enu\sqljdbc.jar
设置SQLEXPRESS服务器:
a.打开SQL Server Configuration Manager -> SQLEXPRESS的协议 -> TCP/IP
b.右键单击启动TCP/IP
c.双击进入属性,把IP地址中的IP all中的TCP端口设置为1433
d.重新启动SQL Server 2005服务中的SQLEXPRESS服务器
e.关闭SQL Server Configuration Manager
打开 SQL Server Management Studio,连接SQLEXPRESS服务器, 新建数据库,起名字为sample
打开Eclipse
a.新建工程-> Java -> Java project,起名为Test
b.选择eclipse->窗口->首选项->Java->installed JRE 编辑已经安装好的jdk,查找目录添加sqljdbc.jar
c.右键单击目录窗口中的Test, 选择Build Path ->Configure Build Path..., 添加扩展jar文件,即把sqljdbc.jar添加到其中
编写Java代码来测试JDBC连接SQL Server数据库
import java.sql.*;
public class Test {
public static void main(String[] srg) {
//加载JDBC驱动
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//连接服务器和数据库sample
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=sample";
String userName = "sa"; //默认用户名
String userPwd = "123456"; //密码
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出
} catch (Exception e) {
e.printStackTrace();
}
}
}
执行以后就可以连接到sample数据库了。
6、怎么连接别的服务器的sqlserver
第一步:确认你的服务器是运行的。在企业管理器中看到服务器处如果有个绿版色的小三角形,表权示运行成功;如果是红色方块,则未成功,如果无法用“启动”连接成功,你需要对着服务器名称点鼠标右键,选择“新建SQL SERVER注册”,然后在弹出的向导对话框中选择“下一步”,然后在出现的“可用的服务器”中选择一个已有的服务器,点“添加”,然后点“下一步”,选择使用“Windows身份验证登录”,然后一路默认点下去,最后完成,就可以启动你的服务器了。 第二步:启动成功后在企业管理器里面的服务器上右键,选属性,在“安全性”中选择验证方式为“SQL SERVER和WINDOWS”,确定。 第三步:打开查询分析器后如果还没有自动连接成功,在连接登录框上选中“如果SQL SERVER已停止,则启动它”,然后选择一个可用服务器(在上面的下拉框右下角的省略号处点击,等一会儿就行)。然后你可以选择用系统验证登录还是用SQL SERVER验证登录,后者需要你有自己的帐号和密码(可以在企业管理器的“安全性”——>“登录”中新建帐号。如果只是为了练习SQL语句,那么推荐使用系统验证,这样方便些
7、SQLServer 哪有win7下载版
....
sql server没有所谓的win7....
现在主流版本是 sql server2000 2005 和2008
一般在win7上推荐使回用 sql server2005 express版本或者答sql server2008的各个版本
8、sqlserver服务器
可以来,但是你自己的机子需要服源务器版本的操作系统。比如你的操作系统是xp,win7等非服务器版本的操作系统,是不可以!(即你的机子要作为服务器来运行,才能为网络上的机子提供服务,操作系统要是服务器<网络>版本的操作系统,装上SQLSERVER2008以后,别机子就能访问了。)
服务器版本的操作系统有:windows2000 server(但是这个不能装SQLSERVER2008),windows2003server ,windows 2008 server等,你自己可以搜下。