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等,你自己可以搜下。