sql server資料庫連線

2022-07-19 03:09:14 字數 1282 閱讀 3238

建立資料庫、表以及有關的sql語句

--建立資料庫

create database winstudent

--建立表

use winstudent

goif exists(select * from sysobjects where name='stuinfo')

drop table stuinfo

create table stuinfo(

stuid nvarchar(12) primary key,

stuname nvarchar(10),

age int default 18

)--插入一條資料

insert into stuinfo (stuid,stuname) values('201207082209','張三');

--插入多條資料

insert into stuinfo (stuid,stuname) values('201207082210','李四'),('201207082211','王五');

--查詢多條語句

select * from stuinfo

連線資料庫**(windows身份 以及 sql server 身份驗證)

/// /// 此函式是通過windows 或 sql server  身份自己連線的sqlserver

///

///

///

private datatable sqlhelper(string commadtext)

catch (exception ex)

}

sqlserver 身份驗證 資料庫設定:

1、通過windows 身份登入到資料庫中

2、安全性--》登入名 滑鼠右鍵 新建登入名

選擇常規,設定登入名以及登入密碼

點選 使用者對映,選擇通過此使用者登入 對映的資料庫,以及使用者角色(如果資料庫無法連線,請檢查此處)

點選 「確定」 之後重啟一下服務,滑鼠右鍵--》重啟服務

資料庫 sql server 身份驗證 配置完成。

二、通過配置檔案連線資料庫

在專案中新增配置檔案,配置檔案中新增**如下:

在程式中,可以讀取配置檔案中的值。讀取連線資料庫字串

資料庫連線 SQLServer

private static logger logger logger.getlogger test.class 驅動 private static final string driver com.microsoft.sqlserver.jdbc.sqlserverdriver 連線路徑 priva...

perl 連線sql server資料庫

本質上是和連線mysql一樣的,但是需要配置很多東西 先看 use dbi my dsn driver server 192.168.1.213 database msy uid perlname pwd x my dbh dbi connect dbi odbc dsn or die couldn...

C 連線SQL Server 資料庫

c 是如何跟sql server進行連線的?在c net程式設計中,離不開ado.net。ado.net是.net連線資料庫的重要元件。使用其可以很方便地訪問資料庫,ado.net還可以訪問oracle資料庫 access資料庫 sql server資料庫等主流的資料庫。使用ado.net連線資料庫...