Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Friday, March 30, 2012

how to create sql server 2005 instance(after uninstalling sql server express)

I have uninsttaled sql server 2005 express then installed sql server 2005 developer edition.All things are installed and working fine like management studio,BOL,reporting services ,e.t.c.

But there is no instance of sql server 2005.I can connect to sql server 2000 instance from management studio.

I have check from all ways but there isn't any instance.

Could I create a instance of sql server 2005 from some where if yes the how.

You can also check my post at sqlteam forum http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=63600

If you run setup again you can create another instance of SQL Server on the same machine. Just give it a new instance name when you run setup.

|||

Thanks Alexander.

I achieve it exactly the same way a week earlier.What I were trying to find is that is there any way we can create an instance without reinstalling full sql server 2005.As at that time when there isn't any instance but i can connect from management studion to sql server 2000.

|||No You need to go through installation again to install a new instance. For speed you can limit what you install to only a new DB Engine which is quicker than installing all the sql server 2005 components again.|||

Thanks alexander.

That indeed increased my knowledge

How to create report parameter programmatically?

Hi,

I'm working on custom report manager. It manages "report entities" and

"report templates" (actually, RDLs uploaded on the server) and stores

one-to-many relation between them. The task is to store

"MasterEntityID" report parameter in every RDL and keep it up in actual

state whether RDL is being assigned to another entity or new RDL is

being uploaded and assigned. I've covered the first issue with

SetReportParameters() web method, but how should I deal with the second

one? Uploaded RDL may be short of the param, so I have to add it

programmatically while uploading.

Thanks,

AnatolyWhat exactly is the second issue? it looks like you have a custom application layer which can have complete control over the parameters.|||Yes, but actually I'm interested in adding new report parameter via web service. My application should do this if a developer of the uploading report hasn't defined necessary parameter manually. Is it possible?|||

The new parameter must be added to the report definition under the <ReportParameters> element. SetReportParameters won't let you configure the new parameter if it is not prior added to the report definition. This makes sense considering that you will probably need also to link the parameter to the report query. In fact, you won't need SetReportParameters for new parameters b/c once you add the parameter to RDL and call SetReportDefinition, the parameter will be created automatically for you.

As a side note, if you your application requires extensive reading/writing to RDL, you may benefit from buidling an object model on top of RDL that knows how to deserialize/serialize from/to RDL to avoid tedious XMLDOM programming and XPATH references.

|||

Teo, thanks for your clear reply. I'd think of object model. Mostly because I'm going to generate some rdl templates (with datasources, datasets and queries definitions) programmatically in future.

Thank you once again and Happy New Year!)

|||Happy New Year to you too.

Wednesday, March 28, 2012

how to create primary keys on compound fields?

Hi everyone,
I am now getting seriously into VB.Net development as a front end to SQL
server. After working about 20 yrs with DBF's and various xBase
programs (dBase, FoxPro, Clipper, etc), I am now convinced VB/SQL is the
way to go
I have a few questions:
I've successfully imported DBF files into SQL server (MSDE) but I can't
seem to create a data adapter (in VB) unless I have a primary key
defined. Do tables require primary keys be defined prior to dragging
them onto a forms and working with datagrids?
How can I create a primary key on a compound field? For a simple key
(one field), I know to open the server explorer, go into design mode,
then right click the field and set primary key. This works well ... but
... what about a 'details' table where the only unique key is a
combination of many fields (might be mixed type too), ex: customer
(char) + item (numeric) + color (char). How does one do that?
Thanks in advance
Richard Fagen
--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
In the table design high-light each column name you want to make PK and
click the PK icon (a gold key symbol) in the toolbar. You high-light
each column by holding down the control key and clicking the square to
the left of the column name.
You could also use a DDL statement to create a PK:
ALTER TABLE table_name ADD CONSTRAINT PK_table_name PRIMARY KEY (col1,
col2, col3)
The coln are the column names that will comprise the PK.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQbTkE4echKqOuFEgEQI7uACg3KvX6c2lJy7M9loRVsXQbs 732YwAnRKD
6CSubCv+n/TA2EUvULyWke2E
=qfj3
--END PGP SIGNATURE--
Richard Fagen wrote:
> Hi everyone,
> I am now getting seriously into VB.Net development as a front end to SQL
> server. After working about 20 yrs with DBF's and various xBase
> programs (dBase, FoxPro, Clipper, etc), I am now convinced VB/SQL is the
> way to go
> I have a few questions:
> I've successfully imported DBF files into SQL server (MSDE) but I can't
> seem to create a data adapter (in VB) unless I have a primary key
> defined. Do tables require primary keys be defined prior to dragging
> them onto a forms and working with datagrids?
> How can I create a primary key on a compound field? For a simple key
> (one field), I know to open the server explorer, go into design mode,
> then right click the field and set primary key. This works well ... but
> ... what about a 'details' table where the only unique key is a
> combination of many fields (might be mixed type too), ex: customer
> (char) + item (numeric) + color (char). How does one do that?
|||Hi,
Thanks for your reply. I never noticed the gold key icon, I was using
the right click popup menu While it appears to work, when I try to
save the changes to the file, I get the same error message...
'PRODUCT' table
- Unable to modify table.
ADO error: Cannot insert the value NULL into column 'PREF', table
'sterilite.dbo.Tmp_PRODUCT'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I imported the DBF files via SQL servers' tools. I thought everything
was ok as in the server explorer, I see the database with all the tables
(foxpro files) inside it. I can also browse the data. I did notice the
'allow nulls' column was checked. I tried unchecking it but I get the
same error.
The foxpro file originally had a 'pref' C4 (for the 'prefix' code, a
character field, width 4) and I don't know what to try next.
In DBF syntax, the unique fields are:
pref, C4 (prefix of item)
item, C4 (item code)
color, C2 (color code)
cu_code, C4 (customer code)
All these fields get translated into 'varchar' type with the appropriate
widths and the allow nulls checked.
Any ideas?
Thanks
Richard
MGFoster wrote:
> --BEGIN PGP SIGNED MESSAGE--
> Hash: SHA1
> In the table design high-light each column name you want to make PK and
> click the PK icon (a gold key symbol) in the toolbar. You high-light
> each column by holding down the control key and clicking the square to
> the left of the column name.
> You could also use a DDL statement to create a PK:
> ALTER TABLE table_name ADD CONSTRAINT PK_table_name PRIMARY KEY (col1,
> col2, col3)
> The coln are the column names that will comprise the PK.
>
|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
In RDBMS (SQL dbs) each row's Primary Key columns require data, i.e.,
they cannot be NULL. The error you're getting means that the PREF
column has NULL values in some, or all, of the imported rows. This
means the columns you've selected for PKs are not a good choice, or you
need to fix the data so there is a value in the PREF column for each
row.
It would seem that the columns item, color, cu_code, would be good
candidates for PK if they always have values per row, and, the 3 column
values, taken together, represent a unique value in the table.
Is the PREF column useful as part of a unique identifier (PK)? If so,
then it should have data.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQbUGaoechKqOuFEgEQK43gCg4pund4SFw+VpPdFrYlcLoG iwV5wAnjzV
aFvBbWaz/Xm1Y1XKxbpzG7wQ
=rrhn
--END PGP SIGNATURE--
Richard Fagen wrote:[vbcol=seagreen]
> Hi,
> Thanks for your reply. I never noticed the gold key icon, I was using
> the right click popup menu While it appears to work, when I try to
> save the changes to the file, I get the same error message...
> 'PRODUCT' table
> - Unable to modify table.
> ADO error: Cannot insert the value NULL into column 'PREF', table
> 'sterilite.dbo.Tmp_PRODUCT'; column does not allow nulls. INSERT fails.
> The statement has been terminated.
> I imported the DBF files via SQL servers' tools. I thought everything
> was ok as in the server explorer, I see the database with all the tables
> (foxpro files) inside it. I can also browse the data. I did notice the
> 'allow nulls' column was checked. I tried unchecking it but I get the
> same error.
> The foxpro file originally had a 'pref' C4 (for the 'prefix' code, a
> character field, width 4) and I don't know what to try next.
> In DBF syntax, the unique fields are:
> pref, C4 (prefix of item)
> item, C4 (item code)
> color, C2 (color code)
> cu_code, C4 (customer code)
> All these fields get translated into 'varchar' type with the appropriate
> widths and the allow nulls checked.
> Any ideas?
> Thanks
> Richard
>
>
> MGFoster wrote:
|||That must be it! Yes, some values of Pref are null. Strange, in the
DBF format it was a blank character field, but when it was imported in
SQL, it became <null>
While I might be able to get around this by excluding 'pref' from the
key, I'll have that problem for other fields as some items don't have
colours and they also appear with <null> in SQL format.
They would still be unique as if an item only comes in one colour, the
DBF file had a blank. Can I globally change all <null> to " " (blank
characters) to fix this.
Thanks for figuring out what the problem was!
Richard
MGFoster wrote:
> --BEGIN PGP SIGNED MESSAGE--
> Hash: SHA1
> In RDBMS (SQL dbs) each row's Primary Key columns require data, i.e.,
> they cannot be NULL. The error you're getting means that the PREF
> column has NULL values in some, or all, of the imported rows. This
> means the columns you've selected for PKs are not a good choice, or you
> need to fix the data so there is a value in the PREF column for each
> row.
> It would seem that the columns item, color, cu_code, would be good
> candidates for PK if they always have values per row, and, the 3 column
> values, taken together, represent a unique value in the table.
> Is the PREF column useful as part of a unique identifier (PK)? If so,
> then it should have data.
>
|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
You can change all values of one column, but that will not fix your
problem. For the PK, what you need to do is pick one, or more, columns
whose values uniquely identify the row. Each of these columns MUST have
data for every row. There cannot be rows where these columns have equal
values. E.g. (the 3 columns that make up the PK):
item colour cu_code
1 2 9988
1 3 9988
1 2 9988 <- PK constraint violation 'cuz equals 1st
row.
It would seem that this table would have a Date column. You could
include the date column in the PK & have something like this:
item colour cu_code order_date
1 2 9988 20040115
1 3 9988 20040115
1 2 9988 20040120 <- now OK 'cuz order_date makes
row different from 1st row.
If the columns you pick as the PK have rows w/o data then you will have
to do, what is known as, "Data Clean Up." Which should be done by your
client since they are the ones who created this mess to begin with.
I suggest you get a good book on database design to help you figure out
construction of primary keys, foreign keys, indexes, etc. I've
recommended _Database Design for Mere Mortals_ by Hernandez.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQbVhPIechKqOuFEgEQLJGQCgjejMWSmlyiNAELht8FvPb2 BluRsAoORW
6ofwJ8Gby1KYNurkiHCb1NM+
=Ode3
--END PGP SIGNATURE--
Richard Fagen wrote:[vbcol=seagreen]
> That must be it! Yes, some values of Pref are null. Strange, in the
> DBF format it was a blank character field, but when it was imported in
> SQL, it became <null>
> While I might be able to get around this by excluding 'pref' from the
> key, I'll have that problem for other fields as some items don't have
> colours and they also appear with <null> in SQL format.
> They would still be unique as if an item only comes in one colour, the
> DBF file had a blank. Can I globally change all <null> to " " (blank
> characters) to fix this.
> Thanks for figuring out what the problem was!
> Richard
> MGFoster wrote:
|||Hi,
Thanks for your prompt reply. I will definitely check out that book. I
have collected quite a library over the years and I'm always reading
many tech books at once
I'm aware of the requirement of a unique value for each record, it is
just some records, when imported from DBF (Foxpro/DOS) have null values.
In DBF format, spaces were stored. I'm not sure why importing the
files into SQL tables cause them to change to <nulls> Maybe I didn't
check off some option during the import process?
Ex:
ItemColourCu_code... more fields here
11Walmart
12Walmart
13Walmart
2<null>Walmart <- problem here, it was blank in the DBF,
some items have a single record that is blank,
it will still be unique, just one " " value
for that cu_code/item combination
31Walmart
32Walmart
Your idea to incorporate another field is a great idea. You are right,
I will have the same problem elsewhere unless I add an orderdate (or
invoice #) to the key. I don't know how to get rid of the <nulls> for
the blank DBFs that were imported into SQL/
I was thinking of replacing the blanks in the DBF with a dummy symbol
(say *) before importing into SQL format. Then I'd use OSQL to replace
the dummy with " ". Is there an easier way?
Thanks again.
Richard
MGFoster wrote:
> --BEGIN PGP SIGNED MESSAGE--
> Hash: SHA1
> You can change all values of one column, but that will not fix your
> problem. For the PK, what you need to do is pick one, or more, columns
> whose values uniquely identify the row. Each of these columns MUST have
> data for every row. There cannot be rows where these columns have equal
> values. E.g. (the 3 columns that make up the PK):
> item colour cu_code
> 1 2 9988
> 1 3 9988
> 1 2 9988 <- PK constraint violation 'cuz equals 1st
> row.
> It would seem that this table would have a Date column. You could
> include the date column in the PK & have something like this:
> item colour cu_code order_date
> 1 2 9988 20040115
> 1 3 9988 20040115
> 1 2 9988 20040120 <- now OK 'cuz order_date makes
> row different from 1st row.
> If the columns you pick as the PK have rows w/o data then you will have
> to do, what is known as, "Data Clean Up." Which should be done by your
> client since they are the ones who created this mess to begin with.
> I suggest you get a good book on database design to help you figure out
> construction of primary keys, foreign keys, indexes, etc. I've
> recommended _Database Design for Mere Mortals_ by Hernandez.
>
|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
It would seem that replacing the "*" with a space would be redundant,
since you're just inserting a "holding character" until you get valid
data, and that holding character can be an asterisk as easily as a
space.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQbYol4echKqOuFEgEQIcRACg0oDX4sr3G7MWGLBjVSDoTU 2tUjgAn3UM
Cg//imB7G3nJKMWBWBZRffvf
=Is8Z
--END PGP SIGNATURE--
Richard Fagen wrote:[vbcol=seagreen]
> Hi,
> Thanks for your prompt reply. I will definitely check out that book. I
> have collected quite a library over the years and I'm always reading
> many tech books at once
> I'm aware of the requirement of a unique value for each record, it is
> just some records, when imported from DBF (Foxpro/DOS) have null values.
> In DBF format, spaces were stored. I'm not sure why importing the
> files into SQL tables cause them to change to <nulls> Maybe I didn't
> check off some option during the import process?
> Ex:
> Item Colour Cu_code ... more fields here
> 1 1 Walmart
> 1 2 Walmart
> 1 3 Walmart
> 2 <null> Walmart <- problem here, it was blank in the DBF,
> some items have a single record that is blank,
> it will still be unique, just one " " value
> for that cu_code/item combination
> 3 1 Walmart
> 3 2 Walmart
> Your idea to incorporate another field is a great idea. You are right,
> I will have the same problem elsewhere unless I add an orderdate (or
> invoice #) to the key. I don't know how to get rid of the <nulls> for
> the blank DBFs that were imported into SQL/
> I was thinking of replacing the blanks in the DBF with a dummy symbol
> (say *) before importing into SQL format. Then I'd use OSQL to replace
> the dummy with " ". Is there an easier way?
> Thanks again.
> Richard
> MGFoster wrote:
|||Can't a blank value (" ") be valid if it is part of a unique compound
key?
There must be some OSQL statement that I can use.
In anycase, is there a simple way to change all the <null> values to
blank spaces? I know I can use the server explorer to browse and edit
values, but certain tables have 1000's of <null> values in certain columns.
Thanks
Richard
MGFoster wrote:

> --BEGIN PGP SIGNED MESSAGE--
> Hash: SHA1
> It would seem that replacing the "*" with a space would be redundant,
> since you're just inserting a "holding character" until you get valid
> data, and that holding character can be an asterisk as easily as a
> space.
>
|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
You can change NULLs to another character(s) using an update like this:
UPDATE table_name
SET column_name = '*'
WHERE column_name IS NULL
I'd use an actual character, 'cuz some query results thru other
applications (MS Access) will seem to be a space (blank), but, in fact,
will be a NULL.
What I was trying to get at is this may not enable a PK to be
established on the columns you want to make a PK, because, putting a
character in the column may not make a unique PK. E.g.:
BEFORE:
item colour cu_code
NULL 1 9998
2 NULL 9998
NULL 1 9998
AFTER:
item colour cu_code
* 1 9998
2 * 9998
* 1 9998 <- violates PK constraint 'cuz equals row 1.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQbY6KoechKqOuFEgEQKgvACfeROn2fzUzR88HCv9HxPmvY Pl3YcAoMM6
lDykLHrwNeYAAUzf6vFHbpmb
=r+De
--END PGP SIGNATURE--
Richard Fagen wrote:[vbcol=seagreen]
> Can't a blank value (" ") be valid if it is part of a unique compound
> key?
> There must be some OSQL statement that I can use.
> In anycase, is there a simple way to change all the <null> values to
> blank spaces? I know I can use the server explorer to browse and edit
> values, but certain tables have 1000's of <null> values in certain columns.
> Thanks
> Richard
>
> MGFoster wrote:
sql

Monday, March 19, 2012

How to create a single reusable alert in SQL Server Agent?

Hi,
I have numerous SQL scripts that run as jobs under SQL Server Agent.
I've been playing with the alert system and got it working using a
test script.
However, it seems that it's not possible to create a single alert and
associate it with every script.
When right-clicking on a job under SQL Server Agent in SSMS and
selecting the 'Alerts' tab and the 'Add...' option, there is no way
to
select an alert that I have already created. So, this forces me to
create a new alert, which basically does exactly the same thing
(raises an alert when the job message contains the word 'error') as
one that I created previously, meaning the only difference will be
the
alert name.
The problem is that I have over a two dozen scripts that I want to
set
an alert on.
Am I missing something or are multiple duplicate scripts the right
way
to go?
Thanks,
Frank.
You can also write a VBScript that sends email alerts using SMTP. This way
you can pass parameters like probably the names of the jobs and call this
script inside your SQL job. This is what I did for log shipping alerts for a
clustered SQL Server 2000 since IMAP is not supported in this scenario
<francis.moore@.gmail.com> wrote in message
news:801cbe16-c882-4f96-bfb6-7dec556ddd50@.j44g2000hsj.googlegroups.com...
> Hi,
> I have numerous SQL scripts that run as jobs under SQL Server Agent.
> I've been playing with the alert system and got it working using a
> test script.
> However, it seems that it's not possible to create a single alert and
> associate it with every script.
> When right-clicking on a job under SQL Server Agent in SSMS and
> selecting the 'Alerts' tab and the 'Add...' option, there is no way
> to
> select an alert that I have already created. So, this forces me to
> create a new alert, which basically does exactly the same thing
> (raises an alert when the job message contains the word 'error') as
> one that I created previously, meaning the only difference will be
> the
> alert name.
> The problem is that I have over a two dozen scripts that I want to
> set
> an alert on.
> Am I missing something or are multiple duplicate scripts the right
> way
> to go?
> Thanks,
> Frank.
|||Tibor,
Thanks for the response.
I'm still confused, although I can see what you are saying.

> When an alert fires, you can specify to execute a job.
I can see that now, but what I want to do is execute a job using SQL
Server Agent and then if that job fails, I want it to trigger an alert
that emails me the fact that the job has failed. I've had a few
occasions recently where batch jobs have failed and it hasn't been
noticed until a day or so later.
In SSMS, when selecting a job under SQL Server Agent | Jobs and right-
clicking, you can get to a Properties dialog for that job.
On that dialog there are some tabs, General, Steps, Schedules, Alerts,
Notifications and Targets.
Selecting Alerts give you a page with a button titled 'Add...' at the
bottom of it.
Clicking 'Add...' brings up a 'New Alert' dialog.
I am expecting to enter details in there to create an alert for that
job.
It allows me to do this once, but when I go to the next job, to create
a similar alert for that job, I can neither pick the alert that I just
created, nor can I create another alert similar to the pervious one as
it says that one like this already exists.
What I would really like to do is create one alert (i.e. when message
contains text like 'error') and then select that to be the alert that
I can use for that job and possibly others as well. However, it
doesn't seem to work like that. So, I'm still confused.
So, is it possible to use alerts as I want to in SQL Server 2005?
And if not, how would you let an operator know that a batch job has
failed (preferably by email)?
Many thanks for your time,
Frank.
|||Tibor,
Once someone points it out to you it's becomes so blatantly
obvious :-)
You're a star!
Many thanks,
Frank.
|||On Nov 27, 12:40 pm, "Tibor Karaszi"
<tibor_please.no.email_kara...@.hotmail.nomail.com> wrote:
> I'm glad you "see the light", Frank.
> Actually, I've always been confused what the "Alert" tab does for a job. I do know what alerts are
> (EventLog, Perfmon and now WMI), but I just failed to understand why we would have an alert tab for
> the job. It just felt ... backwards. You configure and alert, and then what job to fire. So your
> post made me investigate what this alert tab (for a job) does and indeed it doesn't bring any new
> functionality, it just allow us to configure that this job is to be fired for an alert - in a pretty
> backwards kind of way (and indeed the same config as you do for the alert).
> --
> Tibor Karaszi, SQL Server MVPhttp://www.karaszi.com/sqlserver/default.asphttp://sqlblog.com/blogs/tibor_karaszi
> <francis.mo...@.gmail.com> wrote in message
> news:d59e3dd6-8aa5-4bea-bc03-515257f5a3b3@.a35g2000prf.googlegroups.com...
>
>
>
> - Show quoted text -
Frank - you should check out the xSQL Software's RSS Reporter for SQL
Server (http://www.xsqlsoftware.com/Product/
Sql_Server_Rss_Reporter.aspx) - it is a great way to notify someone on
the status of SQL Server Jobs. It automatically generates RSS feeds
that aggregate job status information from multiple servers - it
avoids the hassles associated with the email notifications, it allows
you to drill down on a job to see what step of it actually failed
etc.
JC

how to create a role in AS 2005 with AMO programmatically

hi All,

I am working on some migration project.it is from AS 2000 to AS 2005.

I have to create a role in AS 2005.Is this one is similer functionality like in AS 2000.

Plz let me know.

I am using AMO for making connection i can able to connect and now i have to create a role,In my previous development we used to create a role in database then after in cube with the help of DSO.Could you please help on this.

if possible if you have any sample to create a role in AS 2005 with AMO please send to me.

Thanks in Advance.

vishu

Hi,

There is a similar discussion about creating roles with AMO in this thread:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1795829&SiteID=1

Adrian Dumitrascu

|||

Hi Adrian,

Thanks for u r quick response,I gone through the link and i checked with the code but it is throwing error finding the database it self.

could u please tell me what could be the problem.because i checked with the same code which u provided in the Post.

Thanks in advance.

|||

If you get an exception in this line:

Database db = s.Databases["the database id"];

then you need to specify the ID of your database instead of the string "the database id". To get the ID of your database, use SQL Management Studio to see the database properties (right click on the Database -> Properties).

Or, if you know the Name of the database, but not the ID, you can use the GetByName method:

Database db = s.Databases.GetByName["the Name of your database"];

Adrian Dumitrascu

|||

Hi

I used below code.FYI.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.AnalysisServices

Public Class ScriptMain

' The execution engine calls this method when the task executes.
' To access the object model, use the Dts object. Connections, variables, events,
' and logging features are available as static members of the Dts class.
' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
'
' To open Code and Text Editor Help, press F1.
' To open Object Browser, press Ctrl+Alt+J.

Public Sub Main()
'
'Connect to SSAS Instance
'--
Dim MyServer As New Server
Dim MyConnectionString As String = "localhost"
MyServer.Connect(MyConnectionString)

'Get Reference to Database
'--
Dim MyDatabase As Database = MyServer.Databases.GetByName("Adventure Works DW")

'Get Reference to Role
'--
Dim MyRole As New Role = MyDatabase.Roles.GetByName("My Role")


'Add Users
'--
Dim MyRoleMember As New RoleMember("TestDomain\TestUser1")
MyRole.Members.Add(MyRoleMember)
MyRole.Update()

'--
MyDatabase.Update() 'This may be optional
MyServer.Disconnect()

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

In above code am getting the error in Dim MyDatabase As Database = MyServer.Databases.GetByName("Adventure Works DW") this line.

is the problem with above code or anything i missed out please let me know.

Thanks in advance.

Regards

vishu.

|||

Is the code running under an account that has permissions to read the "Adventure Works DW" database ? Try to temporary add the account as a server admin or as a database admin (you can do that with SQL Management Studio, right click on the server item -> Properties -> Security tab).

If this was the problem (lack of read permissions) you will need to setup a database role for that account, with read metadata and also write permissions.

Adrian Dumitrascu

|||

Hi

Thanks for the reply,i tried with what you said.

But there i can add only my NT Id only i cant see the permissions for read metadata.

still am getting the same problem.

|||

To temporary add the user as a server administrator, you only need to add it as a member in the Security tab of the server properties dialog in SQL Management Studio.

If that doesn't fix the problem, we need to double check 2 things:

1. make sure your code connects to the server you want

2. run SQL Management Studio under the account you run the code ('Run As' works), connect to the server from #1, right click on the Adventure Works DW database -> Properties and verify that the ID of the database is the one you use in the code

If in step #2 you do not see the Adventure Works database, we need to see if it's a permissions problem (although it should not be since you added the user as server admin) or you don't have the database on that server (connect with other users or check the data folder from "%ProgramFiles%\Microsoft SQL Server").

Adrian Dumitrascu

how to create a role in AS 2005 with AMO programmatically

hi All,

I am working on some migration project.it is from AS 2000 to AS 2005.

I have to create a role in AS 2005.Is this one is similer functionality like in AS 2000.

Plz let me know.

I am using AMO for making connection i can able to connect and now i have to create a role,In my previous development we used to create a role in database then after in cube with the help of DSO.Could you please help on this.

if possible if you have any sample to create a role in AS 2005 with AMO please send to me.

Thanks in Advance.

vishu

Hi,

There is a similar discussion about creating roles with AMO in this thread:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1795829&SiteID=1

Adrian Dumitrascu

|||

Hi Adrian,

Thanks for u r quick response,I gone through the link and i checked with the code but it is throwing error finding the database it self.

could u please tell me what could be the problem.because i checked with the same code which u provided in the Post.

Thanks in advance.

|||

If you get an exception in this line:

Database db = s.Databases["the database id"];

then you need to specify the ID of your database instead of the string "the database id". To get the ID of your database, use SQL Management Studio to see the database properties (right click on the Database -> Properties).

Or, if you know the Name of the database, but not the ID, you can use the GetByName method:

Database db = s.Databases.GetByName["the Name of your database"];

Adrian Dumitrascu

|||

Hi

I used below code.FYI.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.AnalysisServices

Public Class ScriptMain

' The execution engine calls this method when the task executes.
' To access the object model, use the Dts object. Connections, variables, events,
' and logging features are available as static members of the Dts class.
' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
'
' To open Code and Text Editor Help, press F1.
' To open Object Browser, press Ctrl+Alt+J.

Public Sub Main()
'
'Connect to SSAS Instance
'--
Dim MyServer As New Server
Dim MyConnectionString As String = "localhost"
MyServer.Connect(MyConnectionString)

'Get Reference to Database
'--
Dim MyDatabase As Database = MyServer.Databases.GetByName("Adventure Works DW")

'Get Reference to Role
'--
Dim MyRole As New Role = MyDatabase.Roles.GetByName("My Role")


'Add Users
'--
Dim MyRoleMember As New RoleMember("TestDomain\TestUser1")
MyRole.Members.Add(MyRoleMember)
MyRole.Update()

'--
MyDatabase.Update() 'This may be optional
MyServer.Disconnect()

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

In above code am getting the error in Dim MyDatabase As Database = MyServer.Databases.GetByName("Adventure Works DW") this line.

is the problem with above code or anything i missed out please let me know.

Thanks in advance.

Regards

vishu.

|||

Is the code running under an account that has permissions to read the "Adventure Works DW" database ? Try to temporary add the account as a server admin or as a database admin (you can do that with SQL Management Studio, right click on the server item -> Properties -> Security tab).

If this was the problem (lack of read permissions) you will need to setup a database role for that account, with read metadata and also write permissions.

Adrian Dumitrascu

|||

Hi

Thanks for the reply,i tried with what you said.

But there i can add only my NT Id only i cant see the permissions for read metadata.

still am getting the same problem.

|||

To temporary add the user as a server administrator, you only need to add it as a member in the Security tab of the server properties dialog in SQL Management Studio.

If that doesn't fix the problem, we need to double check 2 things:

1. make sure your code connects to the server you want

2. run SQL Management Studio under the account you run the code ('Run As' works), connect to the server from #1, right click on the Adventure Works DW database -> Properties and verify that the ID of the database is the one you use in the code

If in step #2 you do not see the Adventure Works database, we need to see if it's a permissions problem (although it should not be since you added the user as server admin) or you don't have the database on that server (connect with other users or check the data folder from "%ProgramFiles%\Microsoft SQL Server").

Adrian Dumitrascu

Monday, March 12, 2012

How to create a new SQL2005 DB?

Hi folks,

i have VSTS installed and TFS beta refresh 3. all is working fine.

How can i use Visual Studio 2005 to create a new database on the remote server? i can connecto to it fine using the 'server explorer' tab .. but of course it only lists databases that currently exist. How can i create a new one?

lastly, i have no installed sql2005 express edition or whatever it is called LOCALLY on my machine. the reason i didn't do this is becuase i was hoping to use the enterprise sql 2005 server.

If your are using the SQLExpress version best thing to do is download and install the SQLExpress Management Studio CTP from microsoft. It basically gives you the same functionality that is in the full SQL2005 versions.

After running the studio and connecting to the database engine you can navigate to the databases node, right click, new, Database then begin configuring all your tables, constraints and security.

The management studio CTP can be had herehttp://www.microsoft.com/downloads/details.aspx?familyid=82AFBD59-57A4-455E-A2D6-1D4C98D40F6E&displaylang=en

|||

Ahh! so this Management Studio is the equivalent to the SQL CLIENT TOOLS for our sql server 2000's?

is there a Management Studio for sql2005? is it found on the sql2005 cd or do we download it?

|||The SQL Management Studio is installed by default in all versions of SQL2005, Eval, Std, Dev and Enterprise. it can be found in Start--All Programs--Microsoft SQL Server 2005--SQL Server Management Studio. The CTP version can be used to connect to any SQL2005 instance on the network. Just choose the Server/Instance from the drop down list in the Connect to Database engine dialogue or manually type the server/instance name.|||

ahh, interesting.

i installed Team Foundation Server beta refresh 3. Part of that is the SQL2005 install. I installed my SQL2005 version using the MS provided UNATTENDED INSTALL file. This file must have excluded the management studio! damn :(

that said, what about clients trying to manage a sql server, where the sqlserver is remote. Are there client tools on the SQL2005 CD?

How to create a login/user & grant rights?

I'm trying to create new login/user account in C#. I'm pretty close to getting it working -- login/user accounts get created, but I'm getting hung up on granting the permissions for the User on the database.

The error that is thrown is:
Microsoft.SqlServer.Management.Smo.FailedOperationException: Grant failed for User 'RTOUser'. > Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. > System.Data.SqlClient.SqlException: Incorrect syntax near 'CONNECT...'.

With the SQL server profiler, I can see the grant command that was used:
GRANT CONNECT, DELETE, EXECUTE, INSERT, SELECT ON USER::[RTOUser] TO [test14]

RTOUser is just a generic testing account I'm using that basically has admin rights on the database. It also has with grant rights for the aforementioned rights being granted to the test user, test14.

How does one post formatted code on here? a [code] bracket doesn't work nor do I see anything in the formatting bar above for it. Below is the code I'm using:

public override Int32 CreateEmployee( EmployeeData emp )
{
Int32 lastid = 0;
SqlParameter[] insert_parms = {
new SqlParameter("@.EmpUserName", SqlDbType.VarChar, STD_VARCHAR),
new SqlParameter("@.EmpFullName", SqlDbType.VarChar, STD_VARCHAR),
new SqlParameter("@.EmpDescription", SqlDbType.VarChar, STD_VARCHAR)
};

insert_parms[0].Value = emp.m_UserName;
insert_parms[1].Value = emp.m_FullName;
insert_parms[2].Value = emp.m_Description;

try
{
Server svr = SqlHelper.GetServerConnection( this.ConnectionString );
Login lg = new Login( svr, emp.m_UserName );

if ( !svr.Logins.Contains( emp.m_UserName ) )
{
lg.LoginType = LoginType.SqlLogin;
lg.PasswordPolicyEnforced = false; //really should be true
lg.DefaultDatabase = DBNAME;
lg.Create( emp.m_Password );

Database db = svr.Databases[DBNAME];
User u = new User( db, this.UserName );
u.Login = emp.m_UserName;
ObjectPermissionSet perms = new ObjectPermissionSet();

//todo: revise permissions
perms.Connect = true;
perms.Select = true;
perms.Insert = true;
perms.Delete = true;
perms.Execute = true;
u.Grant( perms, emp.m_UserName );
u.Create();

try
{
int.TryParse( SqlHelper.ExecuteScalar( this.DBSqlConnection, CommandType.Text, SQL_INSERT_EMPLOYEE, insert_parms ).ToString(), out lastid );
}
catch(SqlException)
{
throw;
}
}
}
catch (SmoException ex)
{
Console.WriteLine( ex );
}

return lastid;
}Additionally,

the User.Login Intellisense in VS2K5 w/SP1 says "Gets the login that is

associated with the database user". This is wrong since it can also

SET it.|||Bah, figured it out. After thinking what the heck SMO was trying to do with that grant command, I realized how it was doing it wrong. The database needs to grant the rights to the user, not a user to another user.

Functional code snippet:

Database db = svr.Databases[DBNAME];
User u = new User( db, emp.m_UserName );
u.Login = emp.m_UserName;
u.Create();

//todo: revise permissions once user groups functional
DatabasePermissionSet perms = new DatabasePermissionSet();
perms.Select = true;
perms.Insert = true;
perms.Delete = true;
perms.Update = true;
perms.Execute = true;

db.Grant( perms, emp.m_UserName );

Wednesday, March 7, 2012

How to count the number of textboxes

Hi all,

In the report I am working on, I have a "textbox39" in a table which has groups. I want to have another "textbox29" outside the table to count the number of "textbox39"s that are actually displayed and also the number of "textbox1"s that have a certain value (e.g. "1") in the final report. I tried to use "Sum(ReportItems!textbox39.Value)" but the compiler complains

Error 1 [rsAggregateReportItemInBody] The Value expression for the textbox 'textbox29' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers. d:\perf\perfreportingproject\PerformanceTestDetails v.3.rdl 0 0

Error 7 [rsReportItemReference] The Value expression for the textbox ‘textbox29’ refers to the report item ‘textbox39’. Report item expressions can only refer to other report items within the same grouping scope or a containing grouping scope. d:\perf\perfreportingproject\PerformanceTestDetails v.3.rdl 0 0

Anybody has any idea how to solve it?

Thanks so much,

Zhiyan

What are you actually trying to do in terms of the data? Are you trying to count how many groups there are? Or count the number of items in a group? Have you tried using the RowCount or RunningValue function on the data fields?|||

Suppose there is a long expression which displays color "Red" and "Green" in textbox39, I want to count the number of Reds and Greens in my report. Now I can get the total number of textbox39s by multipling the number rows and columns. But when I tried to count the colors, the compiler complains:

Error 1 [rsAggregateofAggregate] The Value expression for the textbox 'textbox27' contains an aggregate function (or RunningValue or RowNumber functions) in the argument to another aggregate function (or RunningValue). Aggregate functions cannot be nested inside other aggregate functions. d:\perf\perfreportingproject\PerformanceTestDetails v.3.rdl 0 0

Error 2 [rsAggregateofAggregate] The Value expression for the textbox 'textbox27' contains an aggregate function (or RunningValue or RowNumber functions) in the argument to another aggregate function (or RunningValue). Aggregate functions cannot be nested inside other aggregate functions. d:\perf\perfreportingproject\PerformanceTestDetails v.3.rdl 0 0

Any ideas?

Thanks!