Showing posts with label knows. Show all posts
Showing posts with label knows. Show all posts

Monday, March 19, 2012

How to get sql server name with a vb-script?

Is there anyone who knows how to get sql server name using a vb-script?

I have tryed this:

bKey = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")

But it cant open it for read.

Someone who knows a better way?

Regards
SW-engineer

I have a script in vb .net but it doesn't target your request

Imports Microsoft.SqlServer.Management.Smo

Dim dt As DataTable

dt = SmoApplication.EnumAvailableSqlServers

For Each dr As DataRow In dt.Rows

MsgBox(dr(0).ToString)

Next

|||You don't specify which machine name you are looking for, but, if you want the name where the package is actually running you can use the SSIS system varaiable MachineName|||

I am not looking for the machine name! I am looking for the name of the sql-server (mssqlserver or sqlexpress)

I need the name when my script creating a database.

What is the "SSIS system varaiable MachineName "?

How work this script in vb.net versus usual vb-script?

Imports Microsoft.SqlServer.Management.Smo

Dim dt As DataTable

dt = SmoApplication.EnumAvailableSqlServers

For Each dr As DataRow In dt.Rows

MsgBox(dr(0).ToString)

Next


|||

That's not the name of the sql-server it's the product version. You need to know whether you are connection to Sql Server of Sql Express? Or are you thinking of the instance name in the case where you have both running on the same machine?

What exactly are you trying to accomplish? With more information we may be able to answer your question.

The system variable MachineName is easy to find. Double-Click a DerivedColumn Shape, and look at the Variables folder in the top left window.

|||

You want the SQL Server instance name you say, not the machine name. Ok, slight problem though since SSIS is not part of the SQL Server instance, so this is a moot point, there is no SQL Server instance associated with SSIS. I could have 10 instances of SQL on a box, but this still has no relationship to SSIS.

SSIS is really just an object model, a set of client-side libraries if you like. There is a SSIS service, but this is not really required, and again has no relationship to any SQL Server instances that may, or may not be installed on the machine as well.

|||

"You need to know whether you are connection to Sql Server of Sql Express? " Yes!

My application can be installed on a machine with mssqlserver or sqlexpress. I need the name when i my script is creating my database.

Here is the code: sqlcmd -S " & WshNetwork.ComputerName & "\sqlexpress -E -i dropp2.sql -i CreateP2DB.sql -i P2T.SQL

As you se here, the name of the sqlserver (here sqlexpress) is hardcoded. I dont want to have the name hardcoded because the machine maybe have mssqlserver installed instead of sqlexpress. I wolud like to read from the machine wich server instance is installed and then choose one of them.

Hope I have made myself clear?

|||

What do you expect to happen if there is an instance of SQLExpress and an instance of SQL Server?

What do you expect to happen if there is more than one instance of SQL Server?

|||

If mssqlserver exist i will choose that server, if only sqlexpress exist i choose that server.

Look here, I would do something like this:

IF(sqlservernnqme == mssqlserver)
...
sqlcmd -S " & WshNetwork.ComputerName & "\mssqlserver -E -i dropp2.sql -i CreateP2DB.sql -i P2T.SQL

else

sqlcmd -S " & WshNetwork.ComputerName & "\sqlexpress -E -i dropp2.sql -i CreateP2DB.sql -i P2T.SQL

|||

You are missing the point I am trying to make. Your simple logic of use SQL but if it is not there use express, will only work in very simple scenario. It may be the most common, but you should not rely on it.

So choosing SQL Server or SQL Express, it is not an either or situation. You can have BOTH SQL Server and SQL Express on the same box. You can have up 50 instances of SQL, be that SQL Server or SQL Express on one machine.

Quite often you can have instances you do not even realise are there as some products install a black box instance that you never see, but any code method will enumerate this instance.

|||

Ok I know what you mean!

My plan is to use either mssqlserver or sqlexpress. If not any of these to instances exist my install project will install sqlexpress and then use sqlexpress.

Is this a bad way to this?

|||

I think you should ask the user. Personally I like to have control of these things. I may have a SQL Server installed, but for a specific app, which I may not want mixed up at all with yours. Similarly I may have this with SQL Express. Detecting what is there and making some recommendations would be good, but I'd always want the choice. I maybe overly pedantic since I obviously I explicitly use SQL.

You could perhaps take the approach of just installing your own named instance of SQLExpress. You can have multiple instances of express if you want, just call yours something other than "SQLExpress" the default name.

|||

That was god arguments!

This application is only installed at computers with me as admin, so I decide which instance the application should use :)

So are there a way to find out the name of the instance?

|||

Try these-

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=337144&SiteId=1

http://www.sqlserver2005.de/articles/1/

|||

Is it not possible to get the name easily with a vb-script?

For example:

to get the windows\system32 directory I just use:

fso.GetSpecialFolder(1)

Is there nothing like this, fso.Getsqlservername(...)

I have been surfing for this many hours now, puh!

How to get sql server name with a vb-script?

Is there anyone who knows how to get sql server name using a vb-script?

I have tryed this:

bKey = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")

But it cant open it for read.

Someone who knows a better way?

Regards
SW-engineer

I have a script in vb .net but it doesn't target your request

Imports Microsoft.SqlServer.Management.Smo

Dim dt As DataTable

dt = SmoApplication.EnumAvailableSqlServers

For Each dr As DataRow In dt.Rows

MsgBox(dr(0).ToString)

Next

|||You don't specify which machine name you are looking for, but, if you want the name where the package is actually running you can use the SSIS system varaiable MachineName|||

I am not looking for the machine name! I am looking for the name of the sql-server (mssqlserver or sqlexpress)

I need the name when my script creating a database.

What is the "SSIS system varaiable MachineName "?

How work this script in vb.net versus usual vb-script?

Imports Microsoft.SqlServer.Management.Smo

Dim dt As DataTable

dt = SmoApplication.EnumAvailableSqlServers

For Each dr As DataRow In dt.Rows

MsgBox(dr(0).ToString)

Next


|||

That's not the name of the sql-server it's the product version. You need to know whether you are connection to Sql Server of Sql Express? Or are you thinking of the instance name in the case where you have both running on the same machine?

What exactly are you trying to accomplish? With more information we may be able to answer your question.

The system variable MachineName is easy to find. Double-Click a DerivedColumn Shape, and look at the Variables folder in the top left window.

|||

You want the SQL Server instance name you say, not the machine name. Ok, slight problem though since SSIS is not part of the SQL Server instance, so this is a moot point, there is no SQL Server instance associated with SSIS. I could have 10 instances of SQL on a box, but this still has no relationship to SSIS.

SSIS is really just an object model, a set of client-side libraries if you like. There is a SSIS service, but this is not really required, and again has no relationship to any SQL Server instances that may, or may not be installed on the machine as well.

|||

"You need to know whether you are connection to Sql Server of Sql Express? " Yes!

My application can be installed on a machine with mssqlserver or sqlexpress. I need the name when i my script is creating my database.

Here is the code: sqlcmd -S " & WshNetwork.ComputerName & "\sqlexpress -E -i dropp2.sql -i CreateP2DB.sql -i P2T.SQL

As you se here, the name of the sqlserver (here sqlexpress) is hardcoded. I dont want to have the name hardcoded because the machine maybe have mssqlserver installed instead of sqlexpress. I wolud like to read from the machine wich server instance is installed and then choose one of them.

Hope I have made myself clear?

|||

What do you expect to happen if there is an instance of SQLExpress and an instance of SQL Server?

What do you expect to happen if there is more than one instance of SQL Server?

|||

If mssqlserver exist i will choose that server, if only sqlexpress exist i choose that server.

Look here, I would do something like this:

IF(sqlservernnqme == mssqlserver)
...
sqlcmd -S " & WshNetwork.ComputerName & "\mssqlserver -E -i dropp2.sql -i CreateP2DB.sql -i P2T.SQL

else

sqlcmd -S " & WshNetwork.ComputerName & "\sqlexpress -E -i dropp2.sql -i CreateP2DB.sql -i P2T.SQL

|||

You are missing the point I am trying to make. Your simple logic of use SQL but if it is not there use express, will only work in very simple scenario. It may be the most common, but you should not rely on it.

So choosing SQL Server or SQL Express, it is not an either or situation. You can have BOTH SQL Server and SQL Express on the same box. You can have up 50 instances of SQL, be that SQL Server or SQL Express on one machine.

Quite often you can have instances you do not even realise are there as some products install a black box instance that you never see, but any code method will enumerate this instance.

|||

Ok I know what you mean!

My plan is to use either mssqlserver or sqlexpress. If not any of these to instances exist my install project will install sqlexpress and then use sqlexpress.

Is this a bad way to this?

|||

I think you should ask the user. Personally I like to have control of these things. I may have a SQL Server installed, but for a specific app, which I may not want mixed up at all with yours. Similarly I may have this with SQL Express. Detecting what is there and making some recommendations would be good, but I'd always want the choice. I maybe overly pedantic since I obviously I explicitly use SQL.

You could perhaps take the approach of just installing your own named instance of SQLExpress. You can have multiple instances of express if you want, just call yours something other than "SQLExpress" the default name.

|||

That was god arguments!

This application is only installed at computers with me as admin, so I decide which instance the application should use :)

So are there a way to find out the name of the instance?

|||

Try these-

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=337144&SiteId=1

http://www.sqlserver2005.de/articles/1/

|||

Is it not possible to get the name easily with a vb-script?

For example:

to get the windows\system32 directory I just use:

fso.GetSpecialFolder(1)

Is there nothing like this, fso.Getsqlservername(...)

I have been surfing for this many hours now, puh!

How to Get SQL Query

Hello,
Just wondering if anyone knows of a way to get the SQL query that a
particular report is using. I keep getting "Unable to set commandtext" when
trying to run a dynamic query and can't figure out why. I don't believe the
query is getting to the server because I cannot see it in SQL profiler.
It would be helpful to know what query reporting services is attempting to
use.
Any help would be greatly appreciated.
Regards,
BenTry the static version of the query first and see if it returns the data
successfully. Then use the dynamic version. Can you post the query
expression?
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Benjamin Pierce" <bpierce@.opentext.com> wrote in message
news:eSg$BqthEHA.1656@.TK2MSFTNGP09.phx.gbl...
> Hello,
> Just wondering if anyone knows of a way to get the SQL query that a
> particular report is using. I keep getting "Unable to set commandtext"
when
> trying to run a dynamic query and can't figure out why. I don't believe
the
> query is getting to the server because I cannot see it in SQL profiler.
> It would be helpful to know what query reporting services is attempting to
> use.
> Any help would be greatly appreciated.
> Regards,
> Ben
>|||Well I've been doing that, but unfortunately it craps out on the dynamic
portion (because there's a heck of a lot of IIF statements). Doesn't MSRS
compile the whole statement into a string first, then send it off to SQL
Server? It would be nice to get the string it compiled so I can know if I
made a typo somewhere rather than doing it the hard way (removing each IIF
statement one by one until I find the typo).
Was hoping there would be a backdoor to get this string...
"Ravi Mumulla (Microsoft)" <ravimu@.online.microsoft.com> wrote in message
news:eSX223thEHA.3944@.tk2msftngp13.phx.gbl...
> Try the static version of the query first and see if it returns the data
> successfully. Then use the dynamic version. Can you post the query
> expression?
> --
> Ravi Mumulla (Microsoft)
> SQL Server Reporting Services
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> "Benjamin Pierce" <bpierce@.opentext.com> wrote in message
> news:eSg$BqthEHA.1656@.TK2MSFTNGP09.phx.gbl...
> > Hello,
> >
> > Just wondering if anyone knows of a way to get the SQL query that a
> > particular report is using. I keep getting "Unable to set commandtext"
> when
> > trying to run a dynamic query and can't figure out why. I don't believe
> the
> > query is getting to the server because I cannot see it in SQL profiler.
> >
> > It would be helpful to know what query reporting services is attempting
to
> > use.
> >
> > Any help would be greatly appreciated.
> >
> > Regards,
> >
> > Ben
> >
> >
>|||What I do is to have a textbox with the expression so I can copy and paste
it into query analyzer. Try this without a dataset until you get what you
want and then go back to creating a dataset.
Bruce L-C
"Benjamin Pierce" <bpierce@.opentext.com> wrote in message
news:eXGcPLuhEHA.632@.TK2MSFTNGP12.phx.gbl...
> Well I've been doing that, but unfortunately it craps out on the dynamic
> portion (because there's a heck of a lot of IIF statements). Doesn't MSRS
> compile the whole statement into a string first, then send it off to SQL
> Server? It would be nice to get the string it compiled so I can know if I
> made a typo somewhere rather than doing it the hard way (removing each IIF
> statement one by one until I find the typo).
> Was hoping there would be a backdoor to get this string...
>
> "Ravi Mumulla (Microsoft)" <ravimu@.online.microsoft.com> wrote in message
> news:eSX223thEHA.3944@.tk2msftngp13.phx.gbl...
> > Try the static version of the query first and see if it returns the data
> > successfully. Then use the dynamic version. Can you post the query
> > expression?
> >
> > --
> > Ravi Mumulla (Microsoft)
> > SQL Server Reporting Services
> >
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > "Benjamin Pierce" <bpierce@.opentext.com> wrote in message
> > news:eSg$BqthEHA.1656@.TK2MSFTNGP09.phx.gbl...
> > > Hello,
> > >
> > > Just wondering if anyone knows of a way to get the SQL query that a
> > > particular report is using. I keep getting "Unable to set
commandtext"
> > when
> > > trying to run a dynamic query and can't figure out why. I don't
believe
> > the
> > > query is getting to the server because I cannot see it in SQL
profiler.
> > >
> > > It would be helpful to know what query reporting services is
attempting
> to
> > > use.
> > >
> > > Any help would be greatly appreciated.
> > >
> > > Regards,
> > >
> > > Ben
> > >
> > >
> >
> >
>|||You can also use SQL Profiler to capture the actual statement being sent to
SQL server.
hth, Mike
"Bruce Loehle-Conger" <bruce_lc@.hotmail.com> wrote in message
news:efgDjZvhEHA.3992@.TK2MSFTNGP11.phx.gbl...
> What I do is to have a textbox with the expression so I can copy and paste
> it into query analyzer. Try this without a dataset until you get what you
> want and then go back to creating a dataset.
> Bruce L-C
> "Benjamin Pierce" <bpierce@.opentext.com> wrote in message
> news:eXGcPLuhEHA.632@.TK2MSFTNGP12.phx.gbl...
> > Well I've been doing that, but unfortunately it craps out on the dynamic
> > portion (because there's a heck of a lot of IIF statements). Doesn't
MSRS
> > compile the whole statement into a string first, then send it off to SQL
> > Server? It would be nice to get the string it compiled so I can know if
I
> > made a typo somewhere rather than doing it the hard way (removing each
IIF
> > statement one by one until I find the typo).
> >
> > Was hoping there would be a backdoor to get this string...
> >
> >
> > "Ravi Mumulla (Microsoft)" <ravimu@.online.microsoft.com> wrote in
message
> > news:eSX223thEHA.3944@.tk2msftngp13.phx.gbl...
> > > Try the static version of the query first and see if it returns the
data
> > > successfully. Then use the dynamic version. Can you post the query
> > > expression?
> > >
> > > --
> > > Ravi Mumulla (Microsoft)
> > > SQL Server Reporting Services
> > >
> > > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> > > "Benjamin Pierce" <bpierce@.opentext.com> wrote in message
> > > news:eSg$BqthEHA.1656@.TK2MSFTNGP09.phx.gbl...
> > > > Hello,
> > > >
> > > > Just wondering if anyone knows of a way to get the SQL query that a
> > > > particular report is using. I keep getting "Unable to set
> commandtext"
> > > when
> > > > trying to run a dynamic query and can't figure out why. I don't
> believe
> > > the
> > > > query is getting to the server because I cannot see it in SQL
> profiler.
> > > >
> > > > It would be helpful to know what query reporting services is
> attempting
> > to
> > > > use.
> > > >
> > > > Any help would be greatly appreciated.
> > > >
> > > > Regards,
> > > >
> > > > Ben
> > > >
> > > >
> > >
> > >
> >
> >
>|||The original post mentions that the SQL statement is not showing up in
profiler.
Could you post your query expression?
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mike Morisoli" <michael@.removeme.vieon.net> wrote in message
news:e%23$l8qwhEHA.4092@.TK2MSFTNGP10.phx.gbl...
> You can also use SQL Profiler to capture the actual statement being sent
to
> SQL server.
> hth, Mike
> "Bruce Loehle-Conger" <bruce_lc@.hotmail.com> wrote in message
> news:efgDjZvhEHA.3992@.TK2MSFTNGP11.phx.gbl...
> > What I do is to have a textbox with the expression so I can copy and
paste
> > it into query analyzer. Try this without a dataset until you get what
you
> > want and then go back to creating a dataset.
> >
> > Bruce L-C
> >
> > "Benjamin Pierce" <bpierce@.opentext.com> wrote in message
> > news:eXGcPLuhEHA.632@.TK2MSFTNGP12.phx.gbl...
> > > Well I've been doing that, but unfortunately it craps out on the
dynamic
> > > portion (because there's a heck of a lot of IIF statements). Doesn't
> MSRS
> > > compile the whole statement into a string first, then send it off to
SQL
> > > Server? It would be nice to get the string it compiled so I can know
if
> I
> > > made a typo somewhere rather than doing it the hard way (removing each
> IIF
> > > statement one by one until I find the typo).
> > >
> > > Was hoping there would be a backdoor to get this string...
> > >
> > >
> > > "Ravi Mumulla (Microsoft)" <ravimu@.online.microsoft.com> wrote in
> message
> > > news:eSX223thEHA.3944@.tk2msftngp13.phx.gbl...
> > > > Try the static version of the query first and see if it returns the
> data
> > > > successfully. Then use the dynamic version. Can you post the query
> > > > expression?
> > > >
> > > > --
> > > > Ravi Mumulla (Microsoft)
> > > > SQL Server Reporting Services
> > > >
> > > > This posting is provided "AS IS" with no warranties, and confers no
> > > rights.
> > > > "Benjamin Pierce" <bpierce@.opentext.com> wrote in message
> > > > news:eSg$BqthEHA.1656@.TK2MSFTNGP09.phx.gbl...
> > > > > Hello,
> > > > >
> > > > > Just wondering if anyone knows of a way to get the SQL query that
a
> > > > > particular report is using. I keep getting "Unable to set
> > commandtext"
> > > > when
> > > > > trying to run a dynamic query and can't figure out why. I don't
> > believe
> > > > the
> > > > > query is getting to the server because I cannot see it in SQL
> > profiler.
> > > > >
> > > > > It would be helpful to know what query reporting services is
> > attempting
> > > to
> > > > > use.
> > > > >
> > > > > Any help would be greatly appreciated.
> > > > >
> > > > > Regards,
> > > > >
> > > > > Ben
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>

Sunday, February 19, 2012

How to get execution progress ?

Does anyone knows how to retrieve execution progress from ssis package, that was
executed programatically.
What I am trying to do, is to launch ssis package on server
and send the progress ("percent complete") to some remote client in order to display it
in progress bar.
I want that ,while ssis package executes, it will raise some event every time the progress changes.

Implement an IDTSEvents interface and pass it to the Execute method.

This Books Online page has more details:

http://technet.microsoft.com/en-us/library/ms135967.aspx

|||I've tried to do that, but without any success.

namespace SSIS_EXEC_SERVER
{
class ExecuteSSIS : IDTSEvents, IHandler
public ExecuteSSIS(I)
{
MyRemotableObjects.Cache.Attach(this);
}

public String fire(string location)
{

Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Microsoft.SqlServer.Dts.Runtime.Package package = new Microsoft.SqlServer.Dts.Runtime.Package();
package = app.LoadPackage(location, this);
package.DesignEvents = this;
Microsoft.SqlServer.Dts.Runtime.DTSExecResult result= package.Execute();

}


IDTSEvents Members
.
.
.
.

}

When I preform package.Execute() the ExecuteSSIS class does not recieve any events.
There is OnProgress method in IDTSEvents and I asumed that it will be informed by the package (there
is PercentComplete paramether in the method).
But still no success...