Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: vbscript

HTVi
TV Discussion Newsgroups

vbscript
"Paul Bergson [MVP-DS]" <pbergson[ at ]allete_nospam.com> 5/30/2007 8:49:08 PM
Could someone point me to a website for examples of vbscripting to a
sqlserver 2005 db?

I need to truncate a SQL Server 2005 table from a remote server and I just
don't want to put any more effort into this than I have to. Microsoft's
script repository isn't of much help.

I have a piece of junk app users have just purchased and when I run a tran
log backup on the db the web server drops the connection to the web server
(How this happens is odd). So I have to go back into sql and truncate a
table and then do an iisreset on the web service. If someone can provide a
different method I'm all ears but I know next to nothing with SQL 2005. I
have limited knowledge with SQL 2000.

--
Paul Bergson
MVP - Directory Services
MCT, MCSE, MCSA, Security+, BS CSci
2003, 2000 (Early Achiever), NT

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup
This posting is provided "AS IS" with no warranties, and confers no rights.


Re: vbscript
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 5/30/2007 10:27:36 PM
Others may know of web sites with examples. I use ADO to create Connection,
Command, and Recordset objects. I assign T-SQL statements to the Source
property of a Recordset object or the CommandText property of a Command
object. The tricky part is taking an SQL statement that works fine in Query
Analyzer and making it into a string. You need to make sure all the spaces,
commas, and single quotes are in the correct places. You also need a
connection string that works in your environment. As far as I know,
everything that worked in SQL Server 2000 works fine in 2005. A made up
example (not tested, so excuse any typos):
================
' Connection string. For the default instance,
' use "SERVER=MyServer".
' This assumes Windows Integrated authentication.
strConnect = "DRIVER=SQL Server;" _
& "Trusted_Connection=Yes;" _
& "DATABASE=MyDatabase;" _
& "SERVER=MyServer\MyInstance"

' Create ADO Command object and connect to database.
Set adoCommand = CreateObject("ADODB.Command")
adoCommand.ActiveConnection = strConnect

' If table Budget exists, delete it.
strSQL = "IF EXISTS " _
& "(" _
& "SELECT TABLE_NAME " _
& "FROM INFORMATION_SCHEMA.TABLES " _
& "WHERE TABLE_NAME = 'Budget'" _
& ") " _
& "DROP TABLE Budget"
adoCommand.CommandText = strSQL
adoCommand.Execute

' Create table Budget.
strSQL = "CREATE TABLE MyDatabase.dbo.Budget " _
& "(" _
& "ItemID INTEGER IDENTITY(1, 1) NOT NULL,
" _
& "Description VARCHAR(25) NULL ,
" _
& "Total MONEY NULL ,
" _
& "CONSTRAINT pk_Budget " _
& "PRIMARY KEY CLUSTERED (ItemID) " _
& "ON [PRIMARY] " _
& ") ON [PRIMARY]"
adoCommand.CommandText = strSQL
adoCommand.Execute

' Insert a row in table Budget.
strSQL = "INSERT INTO MyDatabase.dbo.Budget " _
& "(Description, Total) " _
& "Values('This is a test', 112.45)"
adoCommand.CommandText = strSQL
adoCommand.Execute

' Backup database.
strBackupPath = "c:\Backups\MyDatabase.bak"
adoCommand.CommandText = "BACKUP DATABASE MyDatabase " _
& "TO DISK='" & strBackupPath & "' " _
& "WITH DESCRIPTION='MyDatabase Backup'"
adoCommand.Execute
================
You can run any T-SQL statements, SQL functions, and any stored procedures.
I hope this helps.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Paul Bergson [MVP-DS]" <pbergson[ at ]allete_nospam.com> wrote in message
news:etDa5vvoHHA.4692[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> Could someone point me to a website for examples of vbscripting to a
> sqlserver 2005 db?
>
> I need to truncate a SQL Server 2005 table from a remote server and I just
> don't want to put any more effort into this than I have to. Microsoft's
> script repository isn't of much help.
>
> I have a piece of junk app users have just purchased and when I run a tran
> log backup on the db the web server drops the connection to the web server
> (How this happens is odd). So I have to go back into sql and truncate a
> table and then do an iisreset on the web service. If someone can provide
> a different method I'm all ears but I know next to nothing with SQL 2005.
> I have limited knowledge with SQL 2000.
>
> --
> Paul Bergson
> MVP - Directory Services
> MCT, MCSE, MCSA, Security+, BS CSci
> 2003, 2000 (Early Achiever), NT
>
> http://www.pbbergs.com
>
> Please no e-mails, any questions should be posted in the NewsGroup
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>


Re: vbscript
"Paul Bergson [MVP-DS]" <pbergson[ at ]allete_nospam.com> 5/31/2007 9:02:57 PM
Sadly, going through some old code, I have done similar things but your
example was so close to what I needed it worked first try.

Thanks!

--
Paul Bergson
MVP - Directory Services
MCT, MCSE, MCSA, Security+, BS CSci
2003, 2000 (Early Achiever), NT

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup
This posting is provided "AS IS" with no warranties, and confers no rights.

"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> wrote in
message news:OSU6RnwoHHA.3968[ at ]TK2MSFTNGP06.phx.gbl...
[Quoted Text]
> Others may know of web sites with examples. I use ADO to create
> Connection, Command, and Recordset objects. I assign T-SQL statements to
> the Source property of a Recordset object or the CommandText property of a
> Command object. The tricky part is taking an SQL statement that works fine
> in Query Analyzer and making it into a string. You need to make sure all
> the spaces, commas, and single quotes are in the correct places. You also
> need a connection string that works in your environment. As far as I know,
> everything that worked in SQL Server 2000 works fine in 2005. A made up
> example (not tested, so excuse any typos):
> ================
> ' Connection string. For the default instance,
> ' use "SERVER=MyServer".
> ' This assumes Windows Integrated authentication.
> strConnect = "DRIVER=SQL Server;" _
> & "Trusted_Connection=Yes;" _
> & "DATABASE=MyDatabase;" _
> & "SERVER=MyServer\MyInstance"
>
> ' Create ADO Command object and connect to database.
> Set adoCommand = CreateObject("ADODB.Command")
> adoCommand.ActiveConnection = strConnect
>
> ' If table Budget exists, delete it.
> strSQL = "IF EXISTS " _
> & "(" _
> & "SELECT TABLE_NAME " _
> & "FROM INFORMATION_SCHEMA.TABLES " _
> & "WHERE TABLE_NAME = 'Budget'" _
> & ") " _
> & "DROP TABLE Budget"
> adoCommand.CommandText = strSQL
> adoCommand.Execute
>
> ' Create table Budget.
> strSQL = "CREATE TABLE MyDatabase.dbo.Budget " _
> & "(" _
> & "ItemID INTEGER IDENTITY(1, 1) NOT NULL,
> " _
> & "Description VARCHAR(25) NULL ,
> " _
> & "Total MONEY NULL ,
> " _
> & "CONSTRAINT pk_Budget " _
> & "PRIMARY KEY CLUSTERED (ItemID) " _
> & "ON [PRIMARY] " _
> & ") ON [PRIMARY]"
> adoCommand.CommandText = strSQL
> adoCommand.Execute
>
> ' Insert a row in table Budget.
> strSQL = "INSERT INTO MyDatabase.dbo.Budget " _
> & "(Description, Total) " _
> & "Values('This is a test', 112.45)"
> adoCommand.CommandText = strSQL
> adoCommand.Execute
>
> ' Backup database.
> strBackupPath = "c:\Backups\MyDatabase.bak"
> adoCommand.CommandText = "BACKUP DATABASE MyDatabase " _
> & "TO DISK='" & strBackupPath & "' " _
> & "WITH DESCRIPTION='MyDatabase Backup'"
> adoCommand.Execute
> ================
> You can run any T-SQL statements, SQL functions, and any stored
> procedures. I hope this helps.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Paul Bergson [MVP-DS]" <pbergson[ at ]allete_nospam.com> wrote in message
> news:etDa5vvoHHA.4692[ at ]TK2MSFTNGP05.phx.gbl...
>> Could someone point me to a website for examples of vbscripting to a
>> sqlserver 2005 db?
>>
>> I need to truncate a SQL Server 2005 table from a remote server and I
>> just don't want to put any more effort into this than I have to.
>> Microsoft's script repository isn't of much help.
>>
>> I have a piece of junk app users have just purchased and when I run a
>> tran log backup on the db the web server drops the connection to the web
>> server (How this happens is odd). So I have to go back into sql and
>> truncate a table and then do an iisreset on the web service. If someone
>> can provide a different method I'm all ears but I know next to nothing
>> with SQL 2005. I have limited knowledge with SQL 2000.
>>
>> --
>> Paul Bergson
>> MVP - Directory Services
>> MCT, MCSE, MCSA, Security+, BS CSci
>> 2003, 2000 (Early Achiever), NT
>>
>> http://www.pbbergs.com
>>
>> Please no e-mails, any questions should be posted in the NewsGroup
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen