1 强制关闭数据库链接
--关闭用户打开的进程处理 USE master go IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) DROP PROCEDURE [dbo].[p_killspid] go create proc p_killspid @dbname varchar(200) --要关闭进程的数据库名 as declare @programName nvarchar(200), @spid nvarchar(20) declare cDblogin cursor for select cast(spid as varchar(20)) AS spid from master..sysprocesses where dbid=db_id(@dbname) open cDblogin fetch next from cDblogin into @spid while @@fetch_status=0 begin --防止自己终止自己的进程 --否则会报错不能用KILL 来终止您自己的进程。 IF @spid <> @@SPID exec( 'kill '+@spid) fetch next from cDblogin into @spid end close cDblogin deallocate cDblogin go --用法 exec p_killspid 'fdoam'
2 数据库链接字符创
第一种在远程的:DBFirst: <add name="ZouminEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="
data source=169.254.22.8;initial catalog=PharmacySystem;user id=sa;password=pass01!;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> 第二种在本地的 DBFirst:
<add name="ZouminEntities"connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="
data source=.;initial catalog=PharmacySystem;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""providerName="System.Data.EntityClient"/>
sa登陆:
"Data Source=.;Initial Catalog=数据库;User ID=sa,pwd=;";
windows登陆
Data Source=.;Initial Catalog=数据库;Integrated Security=True
Code First
<add name="PharmacySystem" providerName="System.Data.SqlClient" connectionString="Data Source=169.254.22.8;Initial Catalog=PharmacySystem;Integrated Security=false;User ID=sa;Password=pass01!" />