Click here to Skip to main content
15,895,740 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL Pin
Colin Angus Mackay6-Oct-05 12:35
Colin Angus Mackay6-Oct-05 12:35 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 11:50
shoaibnawaz7-Oct-05 11:50 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 12:09
shoaibnawaz7-Oct-05 12:09 
GeneralRe: SQL Pin
Colin Angus Mackay7-Oct-05 13:12
Colin Angus Mackay7-Oct-05 13:12 
QuestionSQL Performance Question Pin
jgallen236-Oct-05 8:29
jgallen236-Oct-05 8:29 
AnswerRe: SQL Performance Question Pin
Colin Angus Mackay6-Oct-05 9:11
Colin Angus Mackay6-Oct-05 9:11 
GeneralRe: SQL Performance Question Pin
jgallen236-Oct-05 9:17
jgallen236-Oct-05 9:17 
QuestionExecuting SQL Script File Pin
KragAapie5-Oct-05 19:32
KragAapie5-Oct-05 19:32 
Hey,
I have sql script files that when loaded into sql query analizer work as expected.

How do I load and execute the entire contents of the file from with in a C# windows
app.

I tried

m_cConn = new SqlConnection();
m_cConn.ConnectionString = sConnStr;
m_cConn.Open();
m_cCmd = new SqlCommand(sSQL);
m_cCmd.Connection = m_cConn;
m_cCmd.ExecuteNonQuery();
m_cConn.Close();

etc..

The sSQL is a string with the contents of the sql file loaded into it.
The file contains DB create / drop, table create / drop, procedure create / drop ,
use, update and insert statements.

Thanks in advance.

For Example:

--create the database
use master
declare @DBName varchar(50)
set @DBName = '[NetPortalDB]'
if exists(select * from sysdatabases where name=@DBName)
drop database [NetPortalDB]

create database [NetPortalDB]
GO

use [NetPortalDB]

-- Adding downtime login
if not exists (select * from master.dbo.syslogins where loginname = N'downtime')
BEGIN
declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'us_english'
if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
select @logindb = N'master'
if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
select @loginlang = @@language
exec sp_addlogin N'downtime', N'downtime', @logindb, @loginlang
END
GO

-- Adding processmore login
if not exists (select * from master.dbo.syslogins where loginname = N'processmore')
BEGIN
declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'us_english'
if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
select @logindb = N'master'
if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
select @loginlang = @@language
exec sp_addlogin N'processmore', null, @logindb, @loginlang
END
GO


if not exists (select * from dbo.sysusers where name = N'downtime' and uid < 16382)
EXEC sp_grantdbaccess N'downtime', N'downtime'
GO

if not exists (select * from dbo.sysusers where name = N'processmore' and uid < 16382)
EXEC sp_grantdbaccess N'ProcessMORe', N'processmore'
GO

then goes on to create tables and populate them


AnswerRe: Executing SQL Script File Pin
Colin Angus Mackay5-Oct-05 21:59
Colin Angus Mackay5-Oct-05 21:59 
QuestionHow to call stored procedure from update statement Pin
iluha5-Oct-05 15:54
iluha5-Oct-05 15:54 
AnswerRe: How to call stored procedure from update statement (edit) Pin
Nic Rowan6-Oct-05 1:55
Nic Rowan6-Oct-05 1:55 
QuestionImport/Export in MS Access Pin
suzie1005-Oct-05 8:38
suzie1005-Oct-05 8:38 
QuestionHelp with Cursors in Stored Procedures Pin
jszpila5-Oct-05 6:33
jszpila5-Oct-05 6:33 
AnswerRe: Help with Cursors in Stored Procedures [long reply] Pin
Colin Angus Mackay5-Oct-05 11:12
Colin Angus Mackay5-Oct-05 11:12 
AnswerRe: Help with Cursors in Stored Procedures [long reply] Pin
jszpila5-Oct-05 11:54
jszpila5-Oct-05 11:54 
GeneralRe: Help with Cursors in Stored Procedures [long reply] Pin
Colin Angus Mackay5-Oct-05 12:16
Colin Angus Mackay5-Oct-05 12:16 
QuestionLooking for the right forum Pin
Michael Hulthin4-Oct-05 21:42
Michael Hulthin4-Oct-05 21:42 
QuestionHow to launch access database and view reports Pin
dw19284-Oct-05 20:36
dw19284-Oct-05 20:36 
Questionadd stored procedures .sql to database Pin
theStorminMormon4-Oct-05 10:32
theStorminMormon4-Oct-05 10:32 
AnswerRe: add stored procedures .sql to database Pin
Colin Angus Mackay4-Oct-05 12:44
Colin Angus Mackay4-Oct-05 12:44 
GeneralRe: add stored procedures .sql to database Pin
theStorminMormon5-Oct-05 2:57
theStorminMormon5-Oct-05 2:57 
GeneralRe: add stored procedures .sql to database Pin
Scott Serl6-Oct-05 11:14
Scott Serl6-Oct-05 11:14 
AnswerRe: add stored procedures .sql to database Pin
Luis Alonso Ramos6-Oct-05 18:45
Luis Alonso Ramos6-Oct-05 18:45 
QuestionUsing SqlConnection without Time out Pin
thainam3-Oct-05 23:13
thainam3-Oct-05 23:13 
AnswerRe: Using SqlConnection without Time out Pin
Colin Angus Mackay4-Oct-05 1:19
Colin Angus Mackay4-Oct-05 1:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.