Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Friday, March 30, 2012

ODBC DSN for SQL Server via script

Hi
I have the below script to create DSN for SQL Server. The problem is this
does not include a username and password option for SQL Server
authentication. Could someone please guide me how to add the username and
password option for authentication to this script?
Many Thanks
Regards
= Script Below ========================
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = "My SQL Server"
strValue = "SQL Server"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
strValueName = "Database"
strValue = "My Database"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValueName = "Driver"
strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValueName = "Server"
strValue = "111.111.111.111"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValueName = "Trusted_Connection"
strValue = "No"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValueAFAIK you can't programmatically store the password.
http://support.microsoft.com/kb/184608
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"John" wrote:
> Hi
> I have the below script to create DSN for SQL Server. The problem is this
> does not include a username and password option for SQL Server
> authentication. Could someone please guide me how to add the username and
> password option for authentication to this script?
> Many Thanks
> Regards
>
> = Script Below ========================> Const HKEY_LOCAL_MACHINE = &H80000002
> strComputer = "."
> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:StdRegProv")
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
> strValueName = "My SQL Server"
> strValue = "SQL Server"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> strValueName = "Database"
> strValue = "My Database"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Driver"
> strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Server"
> strValue = "111.111.111.111"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Trusted_Connection"
> strValue = "No"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
>|||To add to Dave's response, the SQL Server ODBC driver does not store the SQL
password for security reasons; anyone with access to the DSN could then
connect to SQL Server. The password needs to be provided by the application
when connecting.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"John" <John@.nospam.infovis.co.uk> wrote in message
news:%23lObOfmiHHA.688@.TK2MSFTNGP03.phx.gbl...
> Hi
> I have the below script to create DSN for SQL Server. The problem is this
> does not include a username and password option for SQL Server
> authentication. Could someone please guide me how to add the username and
> password option for authentication to this script?
> Many Thanks
> Regards
>
> = Script Below ========================> Const HKEY_LOCAL_MACHINE = &H80000002
> strComputer = "."
> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:StdRegProv")
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
> strValueName = "My SQL Server"
> strValue = "SQL Server"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> strValueName = "Database"
> strValue = "My Database"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Driver"
> strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Server"
> strValue = "111.111.111.111"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Trusted_Connection"
> strValue = "No"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
>|||what are you doing?
SQL linked tables in a MDB?
you should jsut use Access Data Projects, kid
"John" <John@.nospam.infovis.co.uk> wrote in message
news:%23lObOfmiHHA.688@.TK2MSFTNGP03.phx.gbl...
> Hi
> I have the below script to create DSN for SQL Server. The problem is this
> does not include a username and password option for SQL Server
> authentication. Could someone please guide me how to add the username and
> password option for authentication to this script?
> Many Thanks
> Regards
>
> = Script Below ========================> Const HKEY_LOCAL_MACHINE = &H80000002
> strComputer = "."
> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:StdRegProv")
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
> strValueName = "My SQL Server"
> strValue = "SQL Server"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
> strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> strValueName = "Database"
> strValue = "My Database"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Driver"
> strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Server"
> strValue = "111.111.111.111"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> strValueName = "Trusted_Connection"
> strValue = "No"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
>|||Dan
crap answers like that is why SQL Server is _STILL_ not secure.
We don't friggin care if you think that it's secure
We don't friggin care what your premise is.
It's goddamn ridiculous that MS refuses to take SQL authentication
seriously.
I GOT CANNED AND BLACKLISTED FROM MICROSOFT FOR COMPLAINING ABOUT SQL
AUTHENTICATION
We just want to create the passwords and use SQL Authentication
I've worked in 100 different SQL Server environments these past 10 years..
and 80% of the clients in the real world use SQL Authentication for
_SOMETHING_.
stfu and take your premise back to MS and tell them to stfu and fix SQL
Authentication
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:418F29B3-9C30-406D-80A5-6B4F1AE9758F@.microsoft.com...
> To add to Dave's response, the SQL Server ODBC driver does not store the
SQL
> password for security reasons; anyone with access to the DSN could then
> connect to SQL Server. The password needs to be provided by the
application
> when connecting.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "John" <John@.nospam.infovis.co.uk> wrote in message
> news:%23lObOfmiHHA.688@.TK2MSFTNGP03.phx.gbl...
> > Hi
> >
> > I have the below script to create DSN for SQL Server. The problem is
this
> > does not include a username and password option for SQL Server
> > authentication. Could someone please guide me how to add the username
and
> > password option for authentication to this script?
> >
> > Many Thanks
> >
> > Regards
> >
> >
> > = Script Below ========================> >
> > Const HKEY_LOCAL_MACHINE = &H80000002
> >
> > strComputer = "."
> >
> > Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> > strComputer & "\root\default:StdRegProv")
> >
> > strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
> > strValueName = "My SQL Server"
> > strValue = "SQL Server"
> > objReg.SetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> >
> > strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> >
> > objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
> >
> > strKeyPath = "SOFTWARE\ODBC\ODBC.INI\My SQL Server"
> >
> > strValueName = "Database"
> > strValue = "My Database"
> > objReg.SetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> >
> > strValueName = "Driver"
> > strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
> > objReg.SetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> >
> > strValueName = "Server"
> > strValue = "111.111.111.111"
> > objReg.SetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> >
> > strValueName = "Trusted_Connection"
> > strValue = "No"
> > objReg.SetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
> >
> >
>

Wednesday, March 28, 2012

ODBC Destination in SSIS

I read that Integration Services does not come with built-in support for ODBC destinations, so I tried to write Script component as destination task.

My destination is odbc for oracle, and it failes with the message:

"Null password given, logon denied".

I can't understand it, I used with the same connection with datareader source and it works.

I spent a long time on this problem, please help me.

Thank you in advance

Noam

How do you create your connection object? Do you just take the connection string from the connection manager or call AcquireConnections on it? If you just take the connection string it will have the password filtered out.

Thanks.

|||

First of all, Thank you for your reply.

You are right, I called the AcquireConnections as you are see:

Public Overrides Sub AcquireConnections(ByVal Transaction As Object)

Dim connectionString As String

connectionString = Me.Connections.Connection.ConnectionString

odbcConn = New OdbcConnection(connectionString)

odbcConn.Open()

End Sub

I changed it, and moved the initialization of the connection to the PreExecute() function.

Now the compilation is succeed, but it is failed at the run time with the same error "Null Password given, logon denied".

Please Help!

Noam

|||

No, as I said before you should not construct your own ODBC connection. Instead, call AcquireConnection on the connection manager and cast the returned object to IDbConnection.

Something Like this:

Dim connection As IDbConnection

connection = Me.Connections.Connection.AcquireConnection(null) as IDbConnection

HTH.

|||

I tried as you suggested.

Dim connection As IDbConnection

connection = Me.Connections.Connection.AcquireConnection(Nothing)

Now, I get This:

"Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Data.IDbConnection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9BB226F4-2AF3-37E7-B91D-3BB936FC0A7E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

I'm stuck with this for 3 days (!!!).

Please your help!

Thanks in advance.

Noam

|||

Is the connection you created ADO.NET for ODBC or native ODBC?

You should use ADO.NET for ODBC.

Thanks.

ODBC Destination in SSIS

I read that Integration Services does not come with built-in support for ODBC destinations, so I tried to write Script component as destination task.

My destination is odbc for oracle, and it failes with the message:

"Null password given, logon denied".

I can't understand it, I used with the same connection with datareader source and it works.

I spent a long time on this problem, please help me.

Thank you in advance

Noam

How do you create your connection object? Do you just take the connection string from the connection manager or call AcquireConnections on it? If you just take the connection string it will have the password filtered out.

Thanks.

|||

First of all, Thank you for your reply.

You are right, I called the AcquireConnections as you are see:

Public Overrides Sub AcquireConnections(ByVal Transaction As Object)

Dim connectionString As String

connectionString = Me.Connections.Connection.ConnectionString

odbcConn = New OdbcConnection(connectionString)

odbcConn.Open()

End Sub

I changed it, and moved the initialization of the connection to the PreExecute() function.

Now the compilation is succeed, but it is failed at the run time with the same error "Null Password given, logon denied".

Please Help!

Noam

|||

No, as I said before you should not construct your own ODBC connection. Instead, call AcquireConnection on the connection manager and cast the returned object to IDbConnection.

Something Like this:

Dim connection As IDbConnection

connection = Me.Connections.Connection.AcquireConnection(null) as IDbConnection

HTH.

|||

I tried as you suggested.

Dim connection As IDbConnection

connection = Me.Connections.Connection.AcquireConnection(Nothing)

Now, I get This:

"Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Data.IDbConnection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9BB226F4-2AF3-37E7-B91D-3BB936FC0A7E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

I'm stuck with this for 3 days (!!!).

Please your help!

Thanks in advance.

Noam

|||

Is the connection you created ADO.NET for ODBC or native ODBC?

You should use ADO.NET for ODBC.

Thanks.

sql

Wednesday, March 7, 2012

Obtaining Scripts

I need to script a couple of things that I do through enterprise manager...is there a way to do a process (such as clear connections/detach database) through enterprise manager and then copy the script that sql ran in the back ground?
Best way is to run profiler and capture the commands while performing your tasks on Ent. Manager.
"Jamie Elliott" wrote:

> I need to script a couple of things that I do through enterprise manager...is there a way to do a process (such as clear connections/detach database) through enterprise manager and then copy the script that sql ran in the back ground?
|||Standart Trace template will be fine ..
"Jamie Elliott" wrote:
[vbcol=seagreen]
> when setting up profiler...is there any certain setting I should give it?
> "Umut Nazlica" wrote:

Obtaining Scripts

I need to script a couple of things that I do through enterprise manager...i
s there a way to do a process (such as clear connections/detach database) th
rough enterprise manager and then copy the script that sql ran in the back g
round?Best way is to run profiler and capture the commands while performing your t
asks on Ent. Manager.
"Jamie Elliott" wrote:

> I need to script a couple of things that I do through enterprise manager...is ther
e a way to do a process (such as clear connections/detach database) through enterpri
se manager and then copy the script that sql ran in the back ground?|||Standart Trace template will be fine ..
"Jamie Elliott" wrote:
[vbcol=seagreen]
> when setting up profiler...is there any certain setting I should give it?
> "Umut Nazlica" wrote:
>

Obtaining PATH to master DB

I need to obtain the path to the master DB in a Wise install script. I know that for SQL2K it is in the registry key:
HKLM\Software\Microsoft\MSSQLServer\Setup

It seems that a SQL2005 installation does not have the same default
directory.

Is there a way to query this from the server itself so I don't have to read the registry?With the usual caveat that it is not a 'best practice' to query the system tables, you can find the answer by executing:

SELECT filename
FROM sysfiles

while connected to the master database. You will get two records. One is the data file, one is the log file. You can narrow the query by adding:

WHERE name = 'master'

Regards,

hmscott

Edit to add: I did verify this against a SQL 2005 instance we are running in development, but it will also work in SQL2K.

Friday, February 24, 2012

Obtain list of backup-able databases

I am currently running a nightly script which obtains the list of databases
from master..sysdatabases and runs DBCC & BACKUP on each of them (including
master/model/msdb)
I have hardcoded the where clause to not select the tempdb, and one database
which I have set as "offline"..
Is it possible to obtain the list of "backupable" databases a little more
efficiently? The database "status" doesn't exactly do the trick, as tempdb
is the same as the other normal db's.
Basically I want to list master/msdb/model & all other ONLINE databases...
Many thanksSelect * from sysdatabases where dbid <>2 and status =24
TempDB always has the id 2.
HTH, Jens Suessmeyer.
"Ben Rum" <bundyrum75@.yahoo.com> schrieb im Newsbeitrag
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
> databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
> (including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
> database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>|||Ben
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
EXEC sp_MSforeachdb--Undocumented sp provided by MS
'IF N''?'' NOT IN(''model'' ,''tempdb'', ''distribution'', ''Northwind'',
''pubs'')
BEGIN
DECLARE @.sql varchar(1000);
set @.sql = ''BACKUP DATABASE '' + (''?'') + '' TO DISK =''''D:\MSSQL2000\MSSQL\BACKUP\'' + (''?'') + ''.bak'''' WITH INIT''
EXEC (@.sql)
END'
"Ben Rum" <bundyrum75@.yahoo.com> wrote in message
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
(including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>|||Hi Jens,
The status of my other databases isn't 24.. It differs depending on the
server.
Server A (SQL 2000) master/msdb = 24, model = 1073741840, other db's = 16,
the offline db = 528
Server B (SQL 7.0) master/msdb = 8, model = 0, other db's = 12 or 4, the
offline db = 1073742438
Thanks
Ben
"Jens Süßmeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:OiDe1ZwSFHA.3544@.TK2MSFTNGP10.phx.gbl...
> Select * from sysdatabases where dbid <>2 and status =24
> TempDB always has the id 2.
> HTH, Jens Suessmeyer.
> "Ben Rum" <bundyrum75@.yahoo.com> schrieb im Newsbeitrag
> news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> >
> > I am currently running a nightly script which obtains the list of
> > databases
> > from master..sysdatabases and runs DBCC & BACKUP on each of them
> > (including
> > master/model/msdb)
> >
> > I have hardcoded the where clause to not select the tempdb, and one
> > database
> > which I have set as "offline"..
> >
> > Is it possible to obtain the list of "backupable" databases a little
more
> > efficiently? The database "status" doesn't exactly do the trick, as
tempdb
> > is the same as the other normal db's.
> >
> > Basically I want to list master/msdb/model & all other ONLINE
databases...
> >
> > Many thanks
> >
> >
>|||Check out the DATABASEPROPERTYEX() in BooksOnLine.
SELECT DATABASEPROPERTYEX('Northwind', Status)
Andrew J. Kelly SQL MVP
"Ben Rum" <bundyrum75@.yahoo.com> wrote in message
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
> databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
> (including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
> database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>

Obtain list of backup-able databases

I am currently running a nightly script which obtains the list of databases
from master..sysdatabases and runs DBCC & BACKUP on each of them (including
master/model/msdb)
I have hardcoded the where clause to not select the tempdb, and one database
which I have set as "offline"..
Is it possible to obtain the list of "backupable" databases a little more
efficiently? The database "status" doesn't exactly do the trick, as tempdb
is the same as the other normal db's.
Basically I want to list master/msdb/model & all other ONLINE databases...
Many thanksSelect * from sysdatabases where dbid <>2 and status =24
TempDB always has the id 2.
HTH, Jens Suessmeyer.
"Ben Rum" <bundyrum75@.yahoo.com> schrieb im Newsbeitrag
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
> databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
> (including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
> database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>|||Ben
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
EXEC sp_MSforeachdb--Undocumented sp provided by MS
'IF N''?'' NOT IN(''model'' ,''tempdb'', ''distribution'', ''Northwind'',
''pubs'')
BEGIN
DECLARE @.sql varchar(1000);
set @.sql = ''BACKUP DATABASE '' + (''?'') + '' TO DISK =
''''D:\MSSQL2000\MSSQL\BACKUP'' + (''?'') + ''.bak'''' WITH INIT''
EXEC (@.sql)
END'
"Ben Rum" <bundyrum75@.yahoo.com> wrote in message
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
(including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>|||Hi Jens,
The status of my other databases isn't 24.. It differs depending on the
server.
Server A (SQL 2000) master/msdb = 24, model = 1073741840, other db's = 16,
the offline db = 528
Server B (SQL 7.0) master/msdb = 8, model = 0, other db's = 12 or 4, the
offline db = 1073742438
Thanks
Ben
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:OiDe1ZwSFHA.3544@.TK2MSFTNGP10.phx.gbl...
> Select * from sysdatabases where dbid <>2 and status =24
> TempDB always has the id 2.
> HTH, Jens Suessmeyer.
> "Ben Rum" <bundyrum75@.yahoo.com> schrieb im Newsbeitrag
> news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
more[vbcol=seagreen]
tempdb[vbcol=seagreen]
databases...[vbcol=seagreen]
>|||Check out the DATABASEPROPERTYEX() in BooksOnLine.
SELECT DATABASEPROPERTYEX('Northwind', Status)
Andrew J. Kelly SQL MVP
"Ben Rum" <bundyrum75@.yahoo.com> wrote in message
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
> databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
> (including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
> database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>

Obtain list of backup-able databases

I am currently running a nightly script which obtains the list of databases
from master..sysdatabases and runs DBCC & BACKUP on each of them (including
master/model/msdb)
I have hardcoded the where clause to not select the tempdb, and one database
which I have set as "offline"..
Is it possible to obtain the list of "backupable" databases a little more
efficiently? The database "status" doesn't exactly do the trick, as tempdb
is the same as the other normal db's.
Basically I want to list master/msdb/model & all other ONLINE databases...
Many thanks
Select * from sysdatabases where dbid <>2 and status =24
TempDB always has the id 2.
HTH, Jens Suessmeyer.
"Ben Rum" <bundyrum75@.yahoo.com> schrieb im Newsbeitrag
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
> databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
> (including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
> database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>
|||Ben
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
EXEC sp_MSforeachdb--Undocumented sp provided by MS
'IF N''?'' NOT IN(''model'' ,''tempdb'', ''distribution'', ''Northwind'',
''pubs'')
BEGIN
DECLARE @.sql varchar(1000);
set @.sql = ''BACKUP DATABASE '' + (''?'') + '' TO DISK =
''''D:\MSSQL2000\MSSQL\BACKUP\'' + (''?'') + ''.bak'''' WITH INIT''
EXEC (@.sql)
END'
"Ben Rum" <bundyrum75@.yahoo.com> wrote in message
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
(including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>
|||Hi Jens,
The status of my other databases isn't 24.. It differs depending on the
server.
Server A (SQL 2000) master/msdb = 24, model = 1073741840, other db's = 16,
the offline db = 528
Server B (SQL 7.0) master/msdb = 8, model = 0, other db's = 12 or 4, the
offline db = 1073742438
Thanks
Ben
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:OiDe1ZwSFHA.3544@.TK2MSFTNGP10.phx.gbl...[vbcol=seagreen]
> Select * from sysdatabases where dbid <>2 and status =24
> TempDB always has the id 2.
> HTH, Jens Suessmeyer.
> "Ben Rum" <bundyrum75@.yahoo.com> schrieb im Newsbeitrag
> news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
more[vbcol=seagreen]
tempdb[vbcol=seagreen]
databases...
>
|||Check out the DATABASEPROPERTYEX() in BooksOnLine.
SELECT DATABASEPROPERTYEX('Northwind', Status)
Andrew J. Kelly SQL MVP
"Ben Rum" <bundyrum75@.yahoo.com> wrote in message
news:uUlhpPwSFHA.2256@.tk2msftngp13.phx.gbl...
> I am currently running a nightly script which obtains the list of
> databases
> from master..sysdatabases and runs DBCC & BACKUP on each of them
> (including
> master/model/msdb)
> I have hardcoded the where clause to not select the tempdb, and one
> database
> which I have set as "offline"..
> Is it possible to obtain the list of "backupable" databases a little more
> efficiently? The database "status" doesn't exactly do the trick, as tempdb
> is the same as the other normal db's.
> Basically I want to list master/msdb/model & all other ONLINE databases...
> Many thanks
>

Monday, February 20, 2012

ObjRecordSet somehow not populating in ActiveX Script

'************************************************* ***********************
' Visual Basic ActiveX Script
'************************************************* ***********************
Option Explicit
Function Main()
Dim objConnection
Dim objRecordSet
Dim strTotal
Dim strPathtoTextFile
DTSGlobalVariables("sSub").Value = "Errors: = "
strtotal = strtotal & DTSGlobalVariables("sSub").Value & "0"
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strPathtoTextFile = "M:\Rep\AA\"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""
objRecordset.Open "SELECT * FROM svcmont.txt", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
Wscript.Echo "Ty: " & objRecordset.Fields.Item("Ty")
Wscript.Echo "Va: " & objRecordset.Fields.Item("Va")
objRecordset.MoveNext
Loop
DTSGlobalVariables("sSub").Value = DTSGlobalVariables("sSub").Value &
objRecordset.Fields.Item("Va")
If strtotal <> DTSGlobalVariables("sSub").Value Then
Main = DTSTaskExecResult_Success
Else
Main = DTSTaskExecResult_Failure
End If
End Function
'************************************************* ***********************
Sample of input file:
Q, 0
QC, 0
Q, 0
Q, 0
Q, 0
QC, 0
Is this a replication script? I think you should repost this in the DTS
group.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Swim" <crombusch@.gmail.com> wrote in message
news:1138049022.892789.174050@.g43g2000cwa.googlegr oups.com...
> '************************************************* ***********************
> ' Visual Basic ActiveX Script
> '************************************************* ***********************
> Option Explicit
> Function Main()
> Dim objConnection
> Dim objRecordSet
> Dim strTotal
> Dim strPathtoTextFile
> DTSGlobalVariables("sSub").Value = "Errors: = "
> strtotal = strtotal & DTSGlobalVariables("sSub").Value & "0"
> On Error Resume Next
> Const adOpenStatic = 3
> Const adLockOptimistic = 3
> Const adCmdText = &H0001
> Set objConnection = CreateObject("ADODB.Connection")
> Set objRecordSet = CreateObject("ADODB.Recordset")
> strPathtoTextFile = "M:\Rep\AA\"
> objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=" & strPathtoTextFile & ";" & _
> "Extended Properties=""text;HDR=NO;FMT=Delimited"""
> objRecordset.Open "SELECT * FROM svcmont.txt", _
> objConnection, adOpenStatic, adLockOptimistic, adCmdText
> Do Until objRecordset.EOF
> Wscript.Echo "Ty: " & objRecordset.Fields.Item("Ty")
> Wscript.Echo "Va: " & objRecordset.Fields.Item("Va")
> objRecordset.MoveNext
> Loop
> DTSGlobalVariables("sSub").Value = DTSGlobalVariables("sSub").Value &
> objRecordset.Fields.Item("Va")
> If strtotal <> DTSGlobalVariables("sSub").Value Then
> Main = DTSTaskExecResult_Success
> Else
> Main = DTSTaskExecResult_Failure
> End If
> End Function
> '************************************************* ***********************
> Sample of input file:
> --
> Q, 0
> QC, 0
> Q, 0
> Q, 0
> Q, 0
> QC, 0
>

Objects in precedence constraints?

Is it possible to use objects in precedence constraints? For example, I have a collection object that may or may not be populated in a script at some point and want to be able to execute different paths depending upon whether the Count property equals zero or not.

I realize I could very easily just create another int variable and populate it accordingly, but I am just curious about this. I couldn't get it to work, but then I am really just starting out here and just not sure if I am doing it wrong.

Thanks!

Brandon

Brandon,

No, its not possible to do that. The expression language doesn't have that capability. You will have to use a script task I'm afraid.

-Jamie