Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Sunday, March 25, 2012

creating a trace definition file (TDF) via code

Is there any way (either TSQL/SMO) to create a new TDF file, I'm using the traceserver InitializeAsReader sub, so need to pass it a reference to a TDF file, and I'd like to control what it traces via the TDF rather than parsing the TextData of the output.

Cathal

There is a Trace API that ships with SMO (see the Microsoft.SqlServer.Management.Trace namespace).

See the TraceServer.InitializeAsReader() method. You can specify a predefine trace template as the second parameter and then start the trace with this template.

|||

Thanks Michiel, but I'm actually using that method already, my question is on the creation of the TDF itself.

Ideally I'd like a t-sql/smo script to generate a TDF template, so I could dynamically determine what events to track and also filter for particular users/databases e.g. if I was only interested in tracking northwind events, I'd create a template based on TSQL_SPs, but that also used a DatabaseName column filter set to like '%Northwind%' . Obviously i can do this manually, but I would like to automate this step for an application I'm writing. I suspect it's not possible to serialize a trace definition to a TDF file. I can use TSQL to create a trace with the correct filters I require, but as I can't pass a running trace to InitializeAsReader, I can't use it. At present I've assumed I'll have to filter the eventData via code, but I thought I'd ask just in case.

Cathal

|||This is not possible, AFAIK. I'll make sure this gets logged as a feature request.

Thursday, March 22, 2012

creating a subscription via an application

Hello,

I am wondering if there is some sample code out there that shows how to create a subscription for a report on reporting services via a win app or if anyone has a better suggestion. We are wanting to have a report that resides on reporting services server be sent to a client via email subscription, but do not want the client to goto the actual website that host reporting services. Thanks in advance.

John

There are SOAP APIs that lets you create subscriptions programmatically. Is that what you are looking for? See the following link for details.

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsmanagementservice2005.reportingservice2005.createsubscription.aspx

Thanks,

Sharmila

|||This was it. Thank you!!

Sunday, March 11, 2012

Creating a Maintenance Plan via the Command Line

Hello All,

I've searched high and low for documentation on this to no avail.

Basically my goal is to create a maintenance plan in SQLSERVER2005 via the command line. I need to create this plan in a way that it can be seen in the list of Maintenance Plans in the Management Studio Interface. I went into the SSIS designer and created my plan. I now have a DTSX file. I tried the dtutil.exe utility, however i never saw my maintenance plan in the list of plans.

I ran dtutil.exe and did /FILE to /SQL but i don't see the plan listed or in a way a user could modify it, which is of the utmost importance to my clients.

How do i get my file to turn into a real running Maintenance Plan that is seen in the list of Maintenance Plans via the Management Studio Interface and is editable by clients?

Other things to keep in mind, i'm attempting to create these via Installshield MSI installer. So i need to do it via command line, or file system-wise. No interface or user interaction.

Please Adivse.

Hi Brendan,

You can use the stored procedures sp_add_maintenance_plan, sp_add_maintenance_plan_db and sp_add_maintenance_plan_job to create maintenance plans, add the databases to it and associate the jobs with the same. Refer documentation on these from Books Online.

Thanks,
Kuntal

|||You have to take help of SQLCMD in this case where using the statements referred above as a Stored procedure, this will do when you want to deploy as the package.|||These three SP's i understand. But how do i reference the file? Or how do i give the plan the 'meat' of what it needs to do? From what i can tell i went to the designer created my dtsx file, and that code in that file need to be input somewhere... can that be done through a sproc as well?|||Anyone?|||

BOL states:

The sqlmaint utility performs a specified set of maintenance operations on one or more databases. Use sqlmaint to run DBCC checks, back up a database and its transaction log, update statistics, and rebuild indexes. All database maintenance activities generate a report that can be sent to a designated text file, HTML file, or e-mail account. sqlmaint executes database maintenance plans created with previous versions of SQL Server. To run SQL Server 2005 maintenance plans from the command prompt, use the dtexec utility utility.

|||

Yeah i wish i could run it like that, but i need it to run in the exact fashion as if it were created in the GUI. Maybe i should explain this better...

I need a programatic way, either through sprocs or command line, to create a maintenance plan, that will show up in the GUI, under maintenance plans, with my name, and have all the steps i specify in the design screen.

Above i see that i run these;

sp_add_maintenance_plan : adds my plan. ok great.

sp_add_maintenance_plan_db : adds a databse that i want to run the plan against, ok great.

sp_add_maintenance_plan_job : ok, adds a job to run my plan. great.

But where does the 'meat' , the steps i designed in the SSIS designer go? all i want to do is add a new maintenance plan that shows in the GUI and has all my steps in the plan. No the steps in the job, the steps in the plan.

I'm sorry, for some reason i cannot wrap my head around this. Thanks for your patience. But i'm not a SQLSERVER admin, i'm an install guy. Any further help would be greatly appreciated.

-b

|||

You can create the SSIS package to perform this maintenace task and you can deploy that SSIS package to multiple servers, http://www.microsoft.com/technet/prodtechnol/sql/2005/mgngssis.mspx#ERGAE fyi.

Drop me an email using my site (contact us) below and I can talk you through the steps.

|||Emailed...|||Anybody have a solution to this? I'm sure it's quite simple, there is just no direct example or i'm not doing this correctly. I'm getting rather desperate here... any help would certainly be appreciated.|||

Brendan

Sorry I didn't get any email from you, could you please send it to smaster@.sqloogle.co.uk.

Brendan Stewart wrote:

Emailed...

Thursday, March 8, 2012

Creating a Maintenance Plan via the Command Line

Hello All,

I've searched high and low for documentation on this to no avail.

Basically my goal is to create a maintenance plan in SQLSERVER2005 via the command line. I need to create this plan in a way that it can be seen in the list of Maintenance Plans in the Management Studio Interface. I went into the SSIS designer and created my plan. I now have a DTSX file. I tried the dtutil.exe utility, however i never saw my maintenance plan in the list of plans.

I ran dtutil.exe and did /FILE to /SQL but i don't see the plan listed or in a way a user could modify it, which is of the utmost importance to my clients.

How do i get my file to turn into a real running Maintenance Plan that is seen in the list of Maintenance Plans via the Management Studio Interface and is editable by clients?

Other things to keep in mind, i'm attempting to create these via Installshield MSI installer. So i need to do it via command line, or file system-wise. No interface or user interaction.

Please Adivse.

Hi Brendan,

You can use the stored procedures sp_add_maintenance_plan, sp_add_maintenance_plan_db and sp_add_maintenance_plan_job to create maintenance plans, add the databases to it and associate the jobs with the same. Refer documentation on these from Books Online.

Thanks,
Kuntal

|||You have to take help of SQLCMD in this case where using the statements referred above as a Stored procedure, this will do when you want to deploy as the package.|||These three SP's i understand. But how do i reference the file? Or how do i give the plan the 'meat' of what it needs to do? From what i can tell i went to the designer created my dtsx file, and that code in that file need to be input somewhere... can that be done through a sproc as well?|||Anyone?|||

BOL states:

The sqlmaint utility performs a specified set of maintenance operations on one or more databases. Use sqlmaint to run DBCC checks, back up a database and its transaction log, update statistics, and rebuild indexes. All database maintenance activities generate a report that can be sent to a designated text file, HTML file, or e-mail account. sqlmaint executes database maintenance plans created with previous versions of SQL Server. To run SQL Server 2005 maintenance plans from the command prompt, use the dtexec utility utility.

|||

Yeah i wish i could run it like that, but i need it to run in the exact fashion as if it were created in the GUI. Maybe i should explain this better...

I need a programatic way, either through sprocs or command line, to create a maintenance plan, that will show up in the GUI, under maintenance plans, with my name, and have all the steps i specify in the design screen.

Above i see that i run these;

sp_add_maintenance_plan : adds my plan. ok great.

sp_add_maintenance_plan_db : adds a databse that i want to run the plan against, ok great.

sp_add_maintenance_plan_job : ok, adds a job to run my plan. great.

But where does the 'meat' , the steps i designed in the SSIS designer go? all i want to do is add a new maintenance plan that shows in the GUI and has all my steps in the plan. No the steps in the job, the steps in the plan.

I'm sorry, for some reason i cannot wrap my head around this. Thanks for your patience. But i'm not a SQLSERVER admin, i'm an install guy. Any further help would be greatly appreciated.

-b

|||

You can create the SSIS package to perform this maintenace task and you can deploy that SSIS package to multiple servers, http://www.microsoft.com/technet/prodtechnol/sql/2005/mgngssis.mspx#ERGAE fyi.

Drop me an email using my site (contact us) below and I can talk you through the steps.

|||Emailed...|||Anybody have a solution to this? I'm sure it's quite simple, there is just no direct example or i'm not doing this correctly. I'm getting rather desperate here... any help would certainly be appreciated.|||

Brendan

Sorry I didn't get any email from you, could you please send it to smaster@.sqloogle.co.uk.

Brendan Stewart wrote:

Emailed...

Wednesday, March 7, 2012

Creating a directory command question

Hi All,

What is the SQL command for creating
a direcotry c:\mydata\data1 on my server.

Thanks in advance
John S

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!"John S" <nospam> wrote in message news:41edfe77$1_1@.127.0.0.1...
> Hi All,
> What is the SQL command for creating
> a direcotry c:\mydata\data1 on my server.
> Thanks in advance
> John S
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

See xp_cmdshell in Books Online. There are security issues with using it, so
it's not a good idea to let end users execute it, but for admin/DBA tasks
it's fine.

Simon

Creating a diagram automatically through Enterprise Manager

Hi all,
I'm wondering, is there any way to have SQL Server automatically generate
a diagram via Enterprise Manager?
The situation is, I have created a database by executing a big as script
of SQL. The script created the tables and views and added the primary key
constraints etc. However there isnt a diagram available to help me understan
d
the schema a bit easier.
Is there some way to have Enterprise Manager interpret the schema and the
constraints and reverse engineer a pretty diagram for me?
Thanks to anyone who can advise
Kindest Regards
tce
Kindest Regards
tceIsn't it as easy as creating a new Diagram and adding all the tables?
Not to belittle the task, but the wizard is pretty good? It isn't the
automated approach but works none the less.
Clint Hill
H3O Software
http://www.h3osoftware.com
thechaosengine wrote:
> Hi all,
> I'm wondering, is there any way to have SQL Server automatically
> generate a diagram via Enterprise Manager?
> The situation is, I have created a database by executing a big as script
> of SQL. The script created the tables and views and added the primary
> key constraints etc. However there isnt a diagram available to help me
> understand the schema a bit easier.
> Is there some way to have Enterprise Manager interpret the schema and
> the constraints and reverse engineer a pretty diagram for me?
> Thanks to anyone who can advise
> Kindest Regards
> tce
> Kindest Regards
> tce
>|||Hi Clint
Thanks for your reply. You are quite right, the wizard does generate the
diagram! I must confess to being a bit stupid here. I normally use Access
connected to SQL Server to develop the database and access doesn't have quit
e
the same functionality in this regard. I actually assumed that the diagramin
g
features were identical. They certainly seem very similar.
Thanks for your help!
Kindest Regards
tce
[vbcol=seagreen]
> Isn't it as easy as creating a new Diagram and adding all the tables?
> Not to belittle the task, but the wizard is pretty good? It isn't the
> automated approach but works none the less.
> Clint Hill
> H3O Software
> http://www.h3osoftware.com
> thechaosengine wrote:
>

Creating a diagram automatically through Enterprise Manager

Hi all,
I'm wondering, is there any way to have SQL Server automatically generate
a diagram via Enterprise Manager?
The situation is, I have created a database by executing a big as script
of SQL. The script created the tables and views and added the primary key
constraints etc. However there isnt a diagram available to help me understand
the schema a bit easier.
Is there some way to have Enterprise Manager interpret the schema and the
constraints and reverse engineer a pretty diagram for me?
Thanks to anyone who can advise
Kindest Regards
tce
Kindest Regards
tce
Isn't it as easy as creating a new Diagram and adding all the tables?
Not to belittle the task, but the wizard is pretty good? It isn't the
automated approach but works none the less.
Clint Hill
H3O Software
http://www.h3osoftware.com
thechaosengine wrote:
> Hi all,
> I'm wondering, is there any way to have SQL Server automatically
> generate a diagram via Enterprise Manager?
> The situation is, I have created a database by executing a big as script
> of SQL. The script created the tables and views and added the primary
> key constraints etc. However there isnt a diagram available to help me
> understand the schema a bit easier.
> Is there some way to have Enterprise Manager interpret the schema and
> the constraints and reverse engineer a pretty diagram for me?
> Thanks to anyone who can advise
> Kindest Regards
> tce
> Kindest Regards
> tce
>
|||Hi Clint
Thanks for your reply. You are quite right, the wizard does generate the
diagram! I must confess to being a bit stupid here. I normally use Access
connected to SQL Server to develop the database and access doesn't have quite
the same functionality in this regard. I actually assumed that the diagraming
features were identical. They certainly seem very similar.
Thanks for your help!
Kindest Regards
tce
[vbcol=seagreen]
> Isn't it as easy as creating a new Diagram and adding all the tables?
> Not to belittle the task, but the wizard is pretty good? It isn't the
> automated approach but works none the less.
> Clint Hill
> H3O Software
> http://www.h3osoftware.com
> thechaosengine wrote:

Creating a diagram automatically through Enterprise Manager

Hi all,
I'm wondering, is there any way to have SQL Server automatically generate
a diagram via Enterprise Manager?
The situation is, I have created a database by executing a big as script
of SQL. The script created the tables and views and added the primary key
constraints etc. However there isnt a diagram available to help me understand
the schema a bit easier.
Is there some way to have Enterprise Manager interpret the schema and the
constraints and reverse engineer a pretty diagram for me?
Thanks to anyone who can advise
Kindest Regards
tce
Kindest Regards
tceIsn't it as easy as creating a new Diagram and adding all the tables?
Not to belittle the task, but the wizard is pretty good? It isn't the
automated approach but works none the less.
Clint Hill
H3O Software
http://www.h3osoftware.com
thechaosengine wrote:
> Hi all,
> I'm wondering, is there any way to have SQL Server automatically
> generate a diagram via Enterprise Manager?
> The situation is, I have created a database by executing a big as script
> of SQL. The script created the tables and views and added the primary
> key constraints etc. However there isnt a diagram available to help me
> understand the schema a bit easier.
> Is there some way to have Enterprise Manager interpret the schema and
> the constraints and reverse engineer a pretty diagram for me?
> Thanks to anyone who can advise
> Kindest Regards
> tce
> Kindest Regards
> tce
>

Saturday, February 25, 2012

Creating a database from script - permissions problems

We deploy our app via ClickOnce. Rather than shipping the .mdf and .ldf, the app detects whether the database is there and creates it via script if it's not. The script was originally generated from SQL Exrpess Mangement Console, etc.

In the past, we've made the stipulation that the user must have administrator access to the machine. However, we now need to find a workable solution for users who are not administrators on their machine. Currently, we use the following connection string before attempting to run the db creation script:

conn.ConnectionString = "Server=.\\sqlexpress;Integrated Security = true;User Instance=false";

The script fails when trying to execute "CREATE DATABASE [myDatabaseName] ON PRIMARY "

with the error:

"CREATE DATABASE permission denied in database 'Master'"

How can we get around this permissions issue in the most automated way possible?

TIA!

Hi,

you will need to have a user with dbcreator permissions, otherwise you won′t be able to make an entry in the sysdatabases (Creating a database). Can you use any administrative SQL Server login to connect to the database and make this possible ? The connection string has to include the userid as well as the password then.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Creating A Dataabas Via SQL Script

I have an SQL script file and what it does is it creates a database with tables and stored procedures, the problem that I have is that I dont know how to execute it, I opened it in VS.NET 2003 but there is no option to execute it anyone know how I can accomplish this. thank you all for your time and patience.If you have the SQL Client installed, you can use Query Analyzer. If not, in theory you could use OSQL.exe (for instance, if you have MSDE and do not have the SQL Client installed). Easier would be to install the SQL client, if you can.|||Where can I get a copy of the SQL client? i do have the OSQL.exe but it's command line and I cant seem to find anything in the help file as to how to run database creating procedures. but I do really appreciated the direction that you set me in. thanks.|||The cheapest way (if you are not an MSDN subscriber) is to get the developers edition, about US$40.00 last time I looked.

The osql utility is typically used in these ways:

a.. Users interactively enter Transact-SQL statements in a manner similar
to working on the command prompt. The results are displayed in the command
prompt window.

b.. Users submit an osql job either specifying a single Transact-SQL
statement to execute or pointing the utility to a text file that contains
Transact-SQL statements to execute. The output is usually directed to a text
file, but it also can be displayed in the command prompt window.
The osql utility uses the ODBC database application programming interface
(API). It is a replacement for the isql command prompt utility based on the
DB-Library API. Both utilities are provided with Microsoft SQL ServerT 2000.
The DB-Library API remains at a SQL Server 6.5 level; therefore,
applications that depend on DB-Library, such as isql, do not support some
SQL Server 2000 features. For example, isql cannot access columns defined
with the ntext data type and truncates any char, varchar, nchar, or nvarchar
columns longer than 255 bytes. It also cannot retrieve results as XML
documents. Except for these limitations in isql, both osql and isql support
the same features

Typing OSQL -? gets you this:

E:\Program Files\Microsoft SQL Server\80\Tools\Binn>osql /?
usage: osql [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w columnwidth]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-L list servers] [-c cmdend] [-D ODBC DSN name]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-n remove numbering] [-m errorlevel]
[-r msgs to stderr] [-V severitylevel]
[-i inputfile] [-o outputfile]
[-p print statistics] [-b On error batch abort]
[-X[1] disable commands [and exit with warning]]
[-O use Old ISQL behavior disables the following]
<EOF> batch processing
Auto console width scaling
Wide messages
default errorlevel is -1 vs 1
[-? show syntax summary]

creating a data driven hierarchial navigation

Hi need to create navigation that gets populated via database and is role based. below is the sql

CREATETABLE [TopMenu](

[MenuID] [int]IDENTITY(1, 1)NOTNULL,

[Text] [varchar](50)COLLATE SQL_Latin1_General_CP1_CI_ASNULL,

[Description] [varchar](255)COLLATE SQL_Latin1_General_CP1_CI_ASNULL,

[ParentID] [int]NULL,

CONSTRAINT [PK_Menu]PRIMARYKEYCLUSTERED

(

[MenuID]

)ON [PRIMARY]

)ON [PRIMARY]

GO

INSERTINTO TopMENU

Select'Property','Property',NULL

UNION ALLSelect'Portfolio','Portfolio',NULL

UNION ALLSelect'Capital Expenditure','PortfolioCapex', 1

UNION ALLSelect'Depreciation','PortfolioDepreciation', 1

UNION ALLSelect'Condition Audit','PortfolioCondition', 1

UNION ALLSelect'Historical Expenditure','PortfolioHisEx', 1

UNION ALLSelect'Property Details','PropertyDetail', 2

UNION ALLSelect'Assets','PropertyAsset', 2

UNION ALLSelect'Depreciation','PropertyDepreciation', 2

UNION ALLSelect'Capital Expenditure','PropertyExpenditure', 2

UNION ALLSelect'Insurance','PropertyInsurance', 2

UNION ALLSelect'Documents','PropertyDocuments', 2

UNION ALLSelect'Capex','PortfolioCapex', 3

UNION ALLSelect'Graph','PortfolioCapexGraph', 3

UNION ALLSelect'Graph','PortfolioDepreciationGraph', 4

UNION ALLSelect'Current Depreciation','PortfolioDepreciation', 4

UNION ALLSelect'WDV & Depreciation','PortfolioDepreciationWDV', 4

UNION ALLSelect'Assets','PropertyAsset', 8

UNION ALLSelect'Capex','PropertyCapex', 8

UNION ALLSelect'Depreciation','PropertyDepreciation', 8

UNION ALLSelect'Condition','PropertyCondition', 8

UNION ALLSelect'Expenditure','PropertyExpenditure', 8

UNION ALLSelect'Disposed','PropertyDisposed', 8

UNION ALLSelect'Capital Ex','PropertyExpenditure', 10

UNION ALLSelect'Capital Ex Graph','PropertyExpenditureGraph', 10

GO

now clearly, I will have two top level navigation

property and portfolio. both property will have subsequent navigation and those subsequest navigation may or may not have another sets of navigation.

I need to display in a row style not in a drop down style for eg. If I am in portfolio link the navigation structure should be as below

Portfolio

Capital Expenditure | Depreciation | Condition Audit | Historical Expenditure

Capex | Graph

by default Capex should be selected. it should also highlight Portfolio, Capital Expenditure and Capex as Capex's parent is Capital Expenditure and Portfolio

I was thinking of using a 3 level datagrid. could someone please help me I am using asp.net 2.0 web application project with vb.net and sql server 2005

thanks in advance

Have you looked at the menu class available from the toolbar? I know it works with a hierarchical xml file, it might work with a database source also.

If it does, I think it will do what you want UI-wise.

|||I am doing it in webform not windows form. does it support that?|||

foremorecoast:

I am doing it in webform not windows form. does it support that?

This is an asp.net forum, not a windows forms forum. So I wasn't talking about windows forms. :)

As for whether it supports database-supplied values instead of xml files for the menu entries, you'll have to look that up. It's what I would do first if I had to code a solution like that. But I don't, and you do, so you can look it up and tell us about what you found. :)

|||

the problem here is not the datasource type but the logic on how to display second level navigation and third level navigation based on what is clicked. i.e. property or portfolio. I have seen lots of article which shows how to create a data driven menu using javascript downdown but i want second and third navigation to be static based on what is clicked( either property or portfolio).

please help

|||

I am thinking of alternative solution using 3 level datalist but its not working as there is no onclick property so that based on property link or portfolio link click i could display their childrens and based on their children click i could display their sub childs.

can anyone please help me?

|||

Hi! I used below method to implement 3 level navigation. but I now have a problem of maintaining the selected state of the item after postback.

when user logs in I need to somehow set the default page pointing to

Portfolio

Assets

Capex

and at the same time i need to show those three links active.

each page should go to differnt url with parameter. below are my codes. please help.

aspx

<asp:DataList ID="dlParent" runat="server" RepeatDirection="Horizontal" DataKeyField="MenuId" OnSelectedIndexChanged="parentselectedindexchanged" Font-Names="Trebuchet MS" Font-Size="Smaller" ForeColor="#404040">
<ItemTemplate>
<asp:LinkButton ID="lnkParent" runat="server" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Text")%>'></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="Silver" />
</asp:DataList>
<asp:dataList id="dlChild" runat="server" RepeatDirection="Horizontal" DataKeyField="MenuId" OnSelectedIndexChanged="childselectedindexchanged" Font-Names="Trebuchet MS" Font-Size="Smaller">
<ItemTemplate>
<asp:LinkButton ID="lnkChild" runat="server" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Text")%>'></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="Silver" />
</asp:dataList>
<asp:dataList id="dlSubChild" runat="server" RepeatDirection="Horizontal" Font-Names="Trebuchet MS" Font-Size="Smaller" >
<ItemTemplate>
<asp:LinkButton ID="lnkSubChild" runat="server" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Text")%>'></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="Silver" />
</asp:dataList>


code behind
--
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myDal As New clsDAL
Dim dsParent As DataSet
'Dim selParent As Integer = -1
'dlParent.SelectedIndex = selParent
If Not IsPostBack Then

dsParent = myDal.getSubMenuItems(0)

If Not dsParent Is Nothing Then
dlParent.DataSource = dsParent
dlParent.DataBind()
End If

End If
End Sub

Protected Function BuildUrl(ByVal field1 As Integer) As String
Dim baseUrl As String
baseUrl = "menu.aspx"
Return String.Format("{0}?navId={1}", baseUrl, field1)
End Function

Public Sub parentselectedindexchanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mydal As New clsDAL
Dim NavId As Integer
'Dim selChild As Integer = -1
'dlChild.SelectedIndex = selChild
Dim dsChild As New DataSet
Try
NavId = CInt(dlParent.DataKeys(dlParent.SelectedIndex))

dsChild = mydal.getSubMenuItems(NavId)
dlChild.DataSource = dsChild
dlChild.DataBind()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End Sub

Public Sub childselectedindexchanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mydal As New clsDAL
Dim NavId As Integer
'Dim selSubChild As Integer = -1
'dlSubChild.SelectedIndex = selSubChild
Dim dsSubChild As New DataSet
Try
NavId = CInt(dlChild.DataKeys(dlChild.SelectedIndex))
dsSubChild = mydal.getSubMenuItems(NavId)
dlSubChild.DataSource = dsSubChild
dlSubChild.DataBind()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End Sub

|||

can someone at least point me to write direction?

|||

You could save the entire object in session cache and restore it with each postback.

Sorry, I don't know how to make it pre-open to a given location.

|||

could you please show me how you will do it as i have never used cache to store the datalist. a code snippet will be of great help.

cheers

Tuesday, February 14, 2012

CREATE via Dynamic SQL into new database?

From a stored procedure running in the context of one database, I would like
to create a set of objects (stored procedures, functions, views, users) into
a newly-created second database, where the name is dynamically determined.
Creating the new database and retrieving its name is no problem, the problem
is executing CREATE FUNCTION, CREATE PROCEDURE, etc. in the context of the
new database.
As you know, executing dynamic SQL 'use database' won't change the context
of an executing procedure. And 'use database; create function ...' doesn't
work, because the create statements need to be in their own batch. I cannot
store the objects in Master, so I can't have them automatically created with
the new database.
Is there a way to copy the objects from an existing (i.e. template) database
to the new one using dynamic SQL? Any way to attach a copy of a template
database file to a new database dynamically?
Or any out-of-the-box ideas?declare @.sql nvarchar(1000)
set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
exec sp_executesql @.sql

> From a stored procedure running in the context of one database, I would
> like to create a set of objects (stored procedures, functions, views,
> users) into a newly-created second database, where the name is dynamically
> determined. Creating the new database and retrieving its name is no
> problem, the problem is executing CREATE FUNCTION, CREATE PROCEDURE, etc.
> in the context of the new database.
> As you know, executing dynamic SQL 'use database' won't change the context
> of an executing procedure. And 'use database; create function ...' doesn't
> work, because the create statements need to be in their own batch. I
> cannot store the objects in Master, so I can't have them automatically
> created with the new database.
> Is there a way to copy the objects from an existing (i.e. template)
> database to the new one using dynamic SQL? Any way to attach a copy of a
> template database file to a new database dynamically?
> Or any out-of-the-box ideas?
new|||here's a real hum-dinger: (this is all on one line)
exec opendatasource('sqloledb', 'data
source=YourServer;uid=UserId;pwd=Passwor
d').YourDatabase.dbo.sp_executesql
N'create table mydatabase.dbo.newtable (myfield1 int)'
You'll want to change the following areas:
YourServer
UserId
Password
YourDatabase
.. and the statement of course

> declare @.sql nvarchar(1000)
> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> exec sp_executesql @.sql
>
>
new|||Thanks, but this isn't the issue. Issue is that from a stored procedure (or
batch, for that matter) running in the context of database A, do:
declare @.DBName varchar(20)
set @.DBName = 'dynamic'
declare @.SQL varchar(200)
set @.SQL = 'use ' + @.DBName + '; create function foo ...'
exec (@.SQL)
Doesn't work because 'create function' must be at the beginning of a batch.
set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
design.
Need to create functions, stored procs etc. in a different,
dynamically-determined database.
"beginthreadex" wrote:

> declare @.sql nvarchar(1000)
> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> exec sp_executesql @.sql
>
> --
> new
>|||LOL ... next it will be sp_cmdshell(osql ... ). :-)
"beginthreadex" wrote:

> here's a real hum-dinger: (this is all on one line)
> exec opendatasource('sqloledb', 'data
> source=YourServer;uid=UserId;pwd=Passwor
d').YourDatabase.dbo.sp_executesql
> N'create table mydatabase.dbo.newtable (myfield1 int)'
> You'll want to change the following areas:
> YourServer
> UserId
> Password
> YourDatabase
> ... and the statement of course
>
> --
> new
>|||The code I provided does execute the code in the other database. Hence, the
"mydatabase" reference. So, here's your code mixed with mine:
declare @.DBName varchar(20)
set @.DBName = 'dynamic'
declare @.SQL varchar(200)
set @.SQL = 'create function [' + @.DBName + '].dbo.foo ...'
exec sp_executesql @.sql
If there is something else that is confusing please let me know. Because I'm
referencing the database name this will run for the context of the other
database.
;)
[vbcol=seagreen]
> Thanks, but this isn't the issue. Issue is that from a stored procedure
> (or batch, for that matter) running in the context of database A, do:
> declare @.DBName varchar(20)
> set @.DBName = 'dynamic'
> declare @.SQL varchar(200)
> set @.SQL = 'use ' + @.DBName + '; create function foo ...'
> exec (@.SQL)
> Doesn't work because 'create function' must be at the beginning of a
> batch.
> set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
> design.
> Need to create functions, stored procs etc. in a different,
> dynamically-determined database.
>|||If you tried it (in s2k), you would realize that you cannot use 3 part
naming for creating procedures or functions. These statements are limited
to accepting an owner name (optional) and an object name.
Try the following statement:
create procedure pubs.dbo.junk as select getdate()|||I deeply apologize! The "Create Table" code does allow for this.
However this DOES work as I have just tested:
exec opendatasource('sqloledb', 'data
source=MySource;uid=MyUID;pwd=MyPWD').pubs.dbo.sp_execsql N'create
procedure dbo.junk as select getdate()'
I know it's not the prettiest, but it DOES work.

> If you tried it (in s2k), you would realize that you cannot use 3 part
> naming for creating procedures or functions. These statements are limited
> to accepting an owner name (optional) and an object name.
> Try the following statement:
> create procedure pubs.dbo.junk as select getdate()
new

CREATE via Dynamic SQL into new database?

From a stored procedure running in the context of one database, I would like
to create a set of objects (stored procedures, functions, views, users) into
a newly-created second database, where the name is dynamically determined.
Creating the new database and retrieving its name is no problem, the problem
is executing CREATE FUNCTION, CREATE PROCEDURE, etc. in the context of the
new database.
As you know, executing dynamic SQL 'use database' won't change the context
of an executing procedure. And 'use database; create function ...' doesn't
work, because the create statements need to be in their own batch. I cannot
store the objects in Master, so I can't have them automatically created with
the new database.
Is there a way to copy the objects from an existing (i.e. template) database
to the new one using dynamic SQL? Any way to attach a copy of a template
database file to a new database dynamically?
Or any out-of-the-box ideas?declare @.sql nvarchar(1000)
set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
exec sp_executesql @.sql
> From a stored procedure running in the context of one database, I would
> like to create a set of objects (stored procedures, functions, views,
> users) into a newly-created second database, where the name is dynamically
> determined. Creating the new database and retrieving its name is no
> problem, the problem is executing CREATE FUNCTION, CREATE PROCEDURE, etc.
> in the context of the new database.
> As you know, executing dynamic SQL 'use database' won't change the context
> of an executing procedure. And 'use database; create function ...' doesn't
> work, because the create statements need to be in their own batch. I
> cannot store the objects in Master, so I can't have them automatically
> created with the new database.
> Is there a way to copy the objects from an existing (i.e. template)
> database to the new one using dynamic SQL? Any way to attach a copy of a
> template database file to a new database dynamically?
> Or any out-of-the-box ideas?
--
new|||here's a real hum-dinger: (this is all on one line)
exec opendatasource('sqloledb', 'data
source=YourServer;uid=UserId;pwd=Password').YourDatabase.dbo.sp_executesql
N'create table mydatabase.dbo.newtable (myfield1 int)'
You'll want to change the following areas:
YourServer
UserId
Password
YourDatabase
... and the statement of course
> declare @.sql nvarchar(1000)
> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> exec sp_executesql @.sql
>
>> From a stored procedure running in the context of one database, I would
>> like to create a set of objects (stored procedures, functions, views,
>> users) into a newly-created second database, where the name is
>> dynamically determined. Creating the new database and retrieving its name
>> is no problem, the problem is executing CREATE FUNCTION, CREATE
>> PROCEDURE, etc. in the context of the new database.
>> As you know, executing dynamic SQL 'use database' won't change the
>> context of an executing procedure. And 'use database; create function
>> ...' doesn't work, because the create statements need to be in their own
>> batch. I cannot store the objects in Master, so I can't have them
>> automatically created with the new database.
>> Is there a way to copy the objects from an existing (i.e. template)
>> database to the new one using dynamic SQL? Any way to attach a copy of a
>> template database file to a new database dynamically?
>> Or any out-of-the-box ideas?
>
--
new|||Thanks, but this isn't the issue. Issue is that from a stored procedure (or
batch, for that matter) running in the context of database A, do:
declare @.DBName varchar(20)
set @.DBName = 'dynamic'
declare @.SQL varchar(200)
set @.SQL = 'use ' + @.DBName + '; create function foo ...'
exec (@.SQL)
Doesn't work because 'create function' must be at the beginning of a batch.
set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
design.
Need to create functions, stored procs etc. in a different,
dynamically-determined database.
"beginthreadex" wrote:
> declare @.sql nvarchar(1000)
> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> exec sp_executesql @.sql
>
> > From a stored procedure running in the context of one database, I would
> > like to create a set of objects (stored procedures, functions, views,
> > users) into a newly-created second database, where the name is dynamically
> > determined. Creating the new database and retrieving its name is no
> > problem, the problem is executing CREATE FUNCTION, CREATE PROCEDURE, etc.
> > in the context of the new database.
> >
> > As you know, executing dynamic SQL 'use database' won't change the context
> > of an executing procedure. And 'use database; create function ...' doesn't
> > work, because the create statements need to be in their own batch. I
> > cannot store the objects in Master, so I can't have them automatically
> > created with the new database.
> >
> > Is there a way to copy the objects from an existing (i.e. template)
> > database to the new one using dynamic SQL? Any way to attach a copy of a
> > template database file to a new database dynamically?
> >
> > Or any out-of-the-box ideas?
> --
> new
>|||LOL ... next it will be sp_cmdshell(osql ... ). :-)
"beginthreadex" wrote:
> here's a real hum-dinger: (this is all on one line)
> exec opendatasource('sqloledb', 'data
> source=YourServer;uid=UserId;pwd=Password').YourDatabase.dbo.sp_executesql
> N'create table mydatabase.dbo.newtable (myfield1 int)'
> You'll want to change the following areas:
> YourServer
> UserId
> Password
> YourDatabase
> ... and the statement of course
>
> > declare @.sql nvarchar(1000)
> > set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> > exec sp_executesql @.sql
> >
> >
> >> From a stored procedure running in the context of one database, I would
> >> like to create a set of objects (stored procedures, functions, views,
> >> users) into a newly-created second database, where the name is
> >> dynamically determined. Creating the new database and retrieving its name
> >> is no problem, the problem is executing CREATE FUNCTION, CREATE
> >> PROCEDURE, etc. in the context of the new database.
> >>
> >> As you know, executing dynamic SQL 'use database' won't change the
> >> context of an executing procedure. And 'use database; create function
> >> ...' doesn't work, because the create statements need to be in their own
> >> batch. I cannot store the objects in Master, so I can't have them
> >> automatically created with the new database.
> >>
> >> Is there a way to copy the objects from an existing (i.e. template)
> >> database to the new one using dynamic SQL? Any way to attach a copy of a
> >> template database file to a new database dynamically?
> >>
> >> Or any out-of-the-box ideas?
> >
> --
> new
>|||The code I provided does execute the code in the other database. Hence, the
"mydatabase" reference. So, here's your code mixed with mine:
declare @.DBName varchar(20)
set @.DBName = 'dynamic'
declare @.SQL varchar(200)
set @.SQL = 'create function [' + @.DBName + '].dbo.foo ...'
exec sp_executesql @.sql
If there is something else that is confusing please let me know. Because I'm
referencing the database name this will run for the context of the other
database.
;)
> Thanks, but this isn't the issue. Issue is that from a stored procedure
> (or batch, for that matter) running in the context of database A, do:
> declare @.DBName varchar(20)
> set @.DBName = 'dynamic'
> declare @.SQL varchar(200)
> set @.SQL = 'use ' + @.DBName + '; create function foo ...'
> exec (@.SQL)
> Doesn't work because 'create function' must be at the beginning of a
> batch.
> set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
> design.
> Need to create functions, stored procs etc. in a different,
> dynamically-determined database.
>
>> declare @.sql nvarchar(1000)
>> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
>> exec sp_executesql @.sql|||If you tried it (in s2k), you would realize that you cannot use 3 part
naming for creating procedures or functions. These statements are limited
to accepting an owner name (optional) and an object name.
Try the following statement:
create procedure pubs.dbo.junk as select getdate()|||Thanks for the response, I really do appreciate it. But CREATE no longer
accepts a DB name reference for functions/procedures - at least in SQL Server
2000.
"beginthreadex" wrote:
> The code I provided does execute the code in the other database. Hence, the
> "mydatabase" reference. So, here's your code mixed with mine:
> declare @.DBName varchar(20)
> set @.DBName = 'dynamic'
> declare @.SQL varchar(200)
> set @.SQL = 'create function [' + @.DBName + '].dbo.foo ...'
> exec sp_executesql @.sql
> If there is something else that is confusing please let me know. Because I'm
> referencing the database name this will run for the context of the other
> database.
> ;)
> > Thanks, but this isn't the issue. Issue is that from a stored procedure
> > (or batch, for that matter) running in the context of database A, do:
> >
> > declare @.DBName varchar(20)
> > set @.DBName = 'dynamic'
> > declare @.SQL varchar(200)
> > set @.SQL = 'use ' + @.DBName + '; create function foo ...'
> > exec (@.SQL)
> >
> > Doesn't work because 'create function' must be at the beginning of a
> > batch.
> >
> > set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
> > design.
> >
> > Need to create functions, stored procs etc. in a different,
> > dynamically-determined database.
> >
> >
> >> declare @.sql nvarchar(1000)
> >> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> >> exec sp_executesql @.sql
>|||I deeply apologize! The "Create Table" code does allow for this.
However this DOES work as I have just tested:
exec opendatasource('sqloledb', 'data
source=MySource;uid=MyUID;pwd=MyPWD').pubs.dbo.sp_execsql N'create
procedure dbo.junk as select getdate()'
I know it's not the prettiest, but it DOES work.
> If you tried it (in s2k), you would realize that you cannot use 3 part
> naming for creating procedures or functions. These statements are limited
> to accepting an owner name (optional) and an object name.
> Try the following statement:
> create procedure pubs.dbo.junk as select getdate()
--
new|||Hello,
I suggest that you refer to the following web site:
http://www.databasejournal.com/features/mssql/article.php/3441031
You may try to use sp_MSforeachdb. I hope the information is helpful.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.

CREATE via Dynamic SQL into new database?

From a stored procedure running in the context of one database, I would like
to create a set of objects (stored procedures, functions, views, users) into
a newly-created second database, where the name is dynamically determined.
Creating the new database and retrieving its name is no problem, the problem
is executing CREATE FUNCTION, CREATE PROCEDURE, etc. in the context of the
new database.
As you know, executing dynamic SQL 'use database' won't change the context
of an executing procedure. And 'use database; create function ...' doesn't
work, because the create statements need to be in their own batch. I cannot
store the objects in Master, so I can't have them automatically created with
the new database.
Is there a way to copy the objects from an existing (i.e. template) database
to the new one using dynamic SQL? Any way to attach a copy of a template
database file to a new database dynamically?
Or any out-of-the-box ideas?
declare @.sql nvarchar(1000)
set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
exec sp_executesql @.sql

> From a stored procedure running in the context of one database, I would
> like to create a set of objects (stored procedures, functions, views,
> users) into a newly-created second database, where the name is dynamically
> determined. Creating the new database and retrieving its name is no
> problem, the problem is executing CREATE FUNCTION, CREATE PROCEDURE, etc.
> in the context of the new database.
> As you know, executing dynamic SQL 'use database' won't change the context
> of an executing procedure. And 'use database; create function ...' doesn't
> work, because the create statements need to be in their own batch. I
> cannot store the objects in Master, so I can't have them automatically
> created with the new database.
> Is there a way to copy the objects from an existing (i.e. template)
> database to the new one using dynamic SQL? Any way to attach a copy of a
> template database file to a new database dynamically?
> Or any out-of-the-box ideas?
new
|||here's a real hum-dinger: (this is all on one line)
exec opendatasource('sqloledb', 'data
source=YourServer;uid=UserId;pwd=Password').YourDa tabase.dbo.sp_executesql
N'create table mydatabase.dbo.newtable (myfield1 int)'
You'll want to change the following areas:
YourServer
UserId
Password
YourDatabase
... and the statement of course

> declare @.sql nvarchar(1000)
> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> exec sp_executesql @.sql
>
>
new
|||Thanks, but this isn't the issue. Issue is that from a stored procedure (or
batch, for that matter) running in the context of database A, do:
declare @.DBName varchar(20)
set @.DBName = 'dynamic'
declare @.SQL varchar(200)
set @.SQL = 'use ' + @.DBName + '; create function foo ...'
exec (@.SQL)
Doesn't work because 'create function' must be at the beginning of a batch.
set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
design.
Need to create functions, stored procs etc. in a different,
dynamically-determined database.
"beginthreadex" wrote:

> declare @.sql nvarchar(1000)
> set @.sql = 'create table mydatabase.dbo.newtable (myfield1 int)'
> exec sp_executesql @.sql
>
> --
> new
>
|||LOL ... next it will be sp_cmdshell(osql ... ). :-)
"beginthreadex" wrote:

> here's a real hum-dinger: (this is all on one line)
> exec opendatasource('sqloledb', 'data
> source=YourServer;uid=UserId;pwd=Password').YourDa tabase.dbo.sp_executesql
> N'create table mydatabase.dbo.newtable (myfield1 int)'
> You'll want to change the following areas:
> YourServer
> UserId
> Password
> YourDatabase
> ... and the statement of course
>
> --
> new
>
|||The code I provided does execute the code in the other database. Hence, the
"mydatabase" reference. So, here's your code mixed with mine:
declare @.DBName varchar(20)
set @.DBName = 'dynamic'
declare @.SQL varchar(200)
set @.SQL = 'create function [' + @.DBName + '].dbo.foo ...'
exec sp_executesql @.sql
If there is something else that is confusing please let me know. Because I'm
referencing the database name this will run for the context of the other
database.
;)
[vbcol=seagreen]
> Thanks, but this isn't the issue. Issue is that from a stored procedure
> (or batch, for that matter) running in the context of database A, do:
> declare @.DBName varchar(20)
> set @.DBName = 'dynamic'
> declare @.SQL varchar(200)
> set @.SQL = 'use ' + @.DBName + '; create function foo ...'
> exec (@.SQL)
> Doesn't work because 'create function' must be at the beginning of a
> batch.
> set @.SQL = 'create function ' + @.DBName + '.dbo.foo ...' doesn't work by
> design.
> Need to create functions, stored procs etc. in a different,
> dynamically-determined database.
>
|||If you tried it (in s2k), you would realize that you cannot use 3 part
naming for creating procedures or functions. These statements are limited
to accepting an owner name (optional) and an object name.
Try the following statement:
create procedure pubs.dbo.junk as select getdate()
|||I deeply apologize! The "Create Table" code does allow for this.
However this DOES work as I have just tested:
exec opendatasource('sqloledb', 'data
source=MySource;uid=MyUID;pwd=MyPWD').pubs.dbo.sp_ execsql N'create
procedure dbo.junk as select getdate()'
I know it's not the prettiest, but it DOES work.

> If you tried it (in s2k), you would realize that you cannot use 3 part
> naming for creating procedures or functions. These statements are limited
> to accepting an owner name (optional) and an object name.
> Try the following statement:
> create procedure pubs.dbo.junk as select getdate()
new