Tuesday, March 27, 2012
Creating a user programmatically
If so, how?check this article:
http://blogs.msdn.com/bryanke/archive/2004/03/17/91736.aspx
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jessica Landisman" <Jessica Landisman@.discussions.microsoft.com> wrote in
message news:D578AACC-3F91-488C-8E69-2E2D8F8420E2@.microsoft.com...
> Can I create a user programmatically (without using the ReportManager
> UI)?
> If so, how?|||Lev,
Thanks for your prompt reply.
In my testing of this blog's suggestion to call GetPolicies() and then
SetPolicies(), SetPolicies only works for a user that is already in the RS
User table. Since I am trying to create a new RS user, that user is not in
the table. An exception is thrown by the SetPolicy method, and the exception
error message is "The user or group name 'Harry.Callahan' is not recognized".
"Lev Semenets [MSFT]" wrote:
> check this article:
> http://blogs.msdn.com/bryanke/archive/2004/03/17/91736.aspx
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Jessica Landisman" <Jessica Landisman@.discussions.microsoft.com> wrote in
> message news:D578AACC-3F91-488C-8E69-2E2D8F8420E2@.microsoft.com...
> > Can I create a user programmatically (without using the ReportManager
> > UI)?
> > If so, how?
>
>|||SetPolicies should add user.
Can you try do it manually (in Report Manager)?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jessica Landisman" <JessicaLandisman@.discussions.microsoft.com> wrote in
message news:6D4AF936-94C3-4C7C-8AA5-558391AD62D5@.microsoft.com...
> Lev,
> Thanks for your prompt reply.
> In my testing of this blog's suggestion to call GetPolicies() and then
> SetPolicies(), SetPolicies only works for a user that is already in the RS
> User table. Since I am trying to create a new RS user, that user is not in
> the table. An exception is thrown by the SetPolicy method, and the
> exception
> error message is "The user or group name 'Harry.Callahan' is not
> recognized".
> "Lev Semenets [MSFT]" wrote:
>> check this article:
>> http://blogs.msdn.com/bryanke/archive/2004/03/17/91736.aspx
>> --
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "Jessica Landisman" <Jessica Landisman@.discussions.microsoft.com> wrote
>> in
>> message news:D578AACC-3F91-488C-8E69-2E2D8F8420E2@.microsoft.com...
>> > Can I create a user programmatically (without using the ReportManager
>> > UI)?
>> > If so, how?
>>|||I can add a user manually in ReportManager.
I have performed SQL traces during when I add a user using ReportManager and
when I attempted to add a user using the code snippet you sent. The SQL
traces are very different.
"Lev Semenets [MSFT]" wrote:
> SetPolicies should add user.
> Can you try do it manually (in Report Manager)?
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Jessica Landisman" <JessicaLandisman@.discussions.microsoft.com> wrote in
> message news:6D4AF936-94C3-4C7C-8AA5-558391AD62D5@.microsoft.com...
> > Lev,
> > Thanks for your prompt reply.
> >
> > In my testing of this blog's suggestion to call GetPolicies() and then
> > SetPolicies(), SetPolicies only works for a user that is already in the RS
> > User table. Since I am trying to create a new RS user, that user is not in
> > the table. An exception is thrown by the SetPolicy method, and the
> > exception
> > error message is "The user or group name 'Harry.Callahan' is not
> > recognized".
> >
> > "Lev Semenets [MSFT]" wrote:
> >
> >> check this article:
> >> http://blogs.msdn.com/bryanke/archive/2004/03/17/91736.aspx
> >>
> >> --
> >> This posting is provided "AS IS" with no warranties, and confers no
> >> rights.
> >>
> >>
> >> "Jessica Landisman" <Jessica Landisman@.discussions.microsoft.com> wrote
> >> in
> >> message news:D578AACC-3F91-488C-8E69-2E2D8F8420E2@.microsoft.com...
> >> > Can I create a user programmatically (without using the ReportManager
> >> > UI)?
> >> > If so, how?
> >>
> >>
> >>
>
>|||that is strange.
Can we take this off this newsgroup?
Could you send me an e-mail?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jessica Landisman" <JessicaLandisman@.discussions.microsoft.com> wrote in
message news:F1631A44-47D7-4F07-B792-790CB03D94EE@.microsoft.com...
>I can add a user manually in ReportManager.
> I have performed SQL traces during when I add a user using ReportManager
> and
> when I attempted to add a user using the code snippet you sent. The SQL
> traces are very different.
> "Lev Semenets [MSFT]" wrote:
>> SetPolicies should add user.
>> Can you try do it manually (in Report Manager)?
>> --
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "Jessica Landisman" <JessicaLandisman@.discussions.microsoft.com> wrote in
>> message news:6D4AF936-94C3-4C7C-8AA5-558391AD62D5@.microsoft.com...
>> > Lev,
>> > Thanks for your prompt reply.
>> >
>> > In my testing of this blog's suggestion to call GetPolicies() and
>> > then
>> > SetPolicies(), SetPolicies only works for a user that is already in the
>> > RS
>> > User table. Since I am trying to create a new RS user, that user is not
>> > in
>> > the table. An exception is thrown by the SetPolicy method, and the
>> > exception
>> > error message is "The user or group name 'Harry.Callahan' is not
>> > recognized".
>> >
>> > "Lev Semenets [MSFT]" wrote:
>> >
>> >> check this article:
>> >> http://blogs.msdn.com/bryanke/archive/2004/03/17/91736.aspx
>> >>
>> >> --
>> >> This posting is provided "AS IS" with no warranties, and confers no
>> >> rights.
>> >>
>> >>
>> >> "Jessica Landisman" <Jessica Landisman@.discussions.microsoft.com>
>> >> wrote
>> >> in
>> >> message news:D578AACC-3F91-488C-8E69-2E2D8F8420E2@.microsoft.com...
>> >> > Can I create a user programmatically (without using the
>> >> > ReportManager
>> >> > UI)?
>> >> > If so, how?
>> >>
>> >>
>> >>
>>
Monday, March 19, 2012
Creating a package with data flow task programmatically
I have created a simple package with 1 data flow task:
Source: data reader (to sql mobile)
Destination: oledb (to sql server)
And the aim is to do a "Select * from table_name" from source and move everything to destination database.
I have followed the steps in documentation, but the package fails! An exception is thrown with message: "Exception from HRESULT: 0xC0202072"
Since its the basic functionality of SSIS that I am implementing, it should work! I have spent 2 whole days trying to make this work and now its high time to ask for help. Can you please have a look!
Thanks,
Pragya
P.S. Any pointers to samples implementing a data flow task programmatically will help too!
Code:
Package package = new Package();
MainPipe dataFlow = ((TaskHost)package.Executables.Add("DTS.Pipeline")).InnerObject as MainPipe;
//Add a SQL Mobile connection manager that is used by the component to the package.
ConnectionManager cm = package.Connections.Add("SQLMOBILE");
cm.Name = "SQL Mobile ConnectionManager";
cm.ConnectionString = "Data Source =D:\\Program Files\\Microsoft Visual Studio 8\\SmartDevices\\SDK\\SQL Server\\Mobile\\v3.0\\Northwind.sdf";
//Add a SQL Server connection manager that will be used later.
ConnectionManager cm1 = package.Connections.Add("OLEDB");
cm1.Name = "SQL Server Connection Manager";
cm1.ConnectionString = "Data Source=SERVERNAME;Initial Catalog=tempdb;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;";
//Adding source component for SQL Mobile.
IDTSComponentMetaData90 component = dataFlow.ComponentMetaDataCollection.New();
component.Name = "ADONETSource";
component.ComponentClassID = "Microsoft.SqlServer.Dts.Pipeline.DataReaderSourceAdapter, Microsoft.SqlServer.ADONETSrc, Version=9.0.242.0, Culture=neutral, blicKeyToken=89845dcd8080cc91";
CManagedComponentWrapper instance = component.Instantiate();
instance.ProvideComponentProperties();
if (component.RuntimeConnectionCollection.Count > 0)
{
component.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.ToConnectionManager90(package.Connections[0]);
}
instance.SetComponentProperty("SqlCommand", "Select * from Employees");
// Reinitialize the metadata.
instance.AcquireConnections(null);
instance.ReinitializeMetaData();
instance.ReleaseConnections();
// Adding destination component for SQL Server
IDTSComponentMetaData90 component1 = dataFlow.ComponentMetaDataCollection.New();
component1.Name = "SQL Server Destination";
component1.ComponentClassID = "DTSAdapter.SqlServerDestination.1";
CManagedComponentWrapper instance1 = component1.Instantiate();
instance1.ProvideComponentProperties();
if (component1.RuntimeConnectionCollection.Count > 0)
{
component1.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.ToConnectionManager90(package.Connections[1]);
}
instance1.SetComponentProperty("BulkInsertKeepIdentity", true);
instance1.SetComponentProperty("BulkInsertKeepNulls", true);
//set path between components
IDTSPath90 path = dataFlow.PathCollection.New();
path.AttachPathAndPropagateNotifications(component.OutputCollection[0], component1.InputCollection[0]); //Assuming this is correct
// WORKS FINE TILL HERE -
// Reinitialize the metadata.
instance1.AcquireConnections(null);
instance1.ReinitializeMetaData(); //Throws exception. Message: "Exception from HRESULT: 0xC0202072" . Even if I reinitialize metadata after iterating through inputs of the component, the same exception is thrown at this statement.
instance1.ReleaseConnections();
// Iterate through the inputs of the component.
foreach (IDTSInput90 input in component1.InputCollection)
{
// Get the virtual input column collection for the input.
IDTSVirtualInput90 vInput = input.GetVirtualInput();
// Iterate through the virtual column collection.
foreach (IDTSVirtualInputColumn90 vColumn in vInput.VirtualInputColumnCollection)
{
// Call the SetUsageType method of the design time instance of the component.
instance1.SetUsageType(input.ID, vInput, vColumn.LineageID, DTSUsageType.UT_READONLY);
}
}
1. You don't set the ConnectionManagerID just the ConnectionManager, but both need to be set.
2. You don't specify a table or sqlstatement for your destination so how does the destination know what table to reinitialize its metadata for?
HTH,
Matt|||1. ConnectionManager.Id is a read only property. How to set it?
2. How can I do that?
Thanks|||
Ok! I got through one step. I added the following line:
instance1.SetComponentProperty("BulkInsertTableName","[Employees]");
to solve this.
However I have related questions,
1. Now the metadata can be initialized, but no rows are being transferred. Something is still amiss...
2. I need to manually create the employees table currently. How can i code the 'create table/view' option so that the table can be generated via code? Do I need to first compile the create table statement with column type information and then execute it using sql client? Is there a better way?
Thanks!
|||Any information on this would help.
Thanks
Sunday, March 11, 2012
Creating a new database programmatically
I've seen several post asking for that possibility, but all 've read, didn't help me.
Some sing SQLDMO, other suggest to use SQLSMO, others only explaining to connect to a server and then do "CREATE DATABASE".
I will do this within .Net. Connecting to a SQL Server 2005 and execute "CREATE DATABASE" I could realize.
But how doing this with SQLExpress? Trying to do SqlConnection.Open with a non existing DB does not work., says "file not exists".
Or do I only have the wrong connection string? Can someone post here an excample connection string, which works with a non existing database?
Some hints I've read make me considering to use SQLSMO. But I don't have it on my computer. Where do I get it from? Any links would be nice.
You are right you can do it with DMO(data management object) and SMO(sql server management objects) but it is better to use ADO.NET ExecuteNoneQuery to create the database and objects. Try the link below for code sample. Hope this helps.
http://www.c-sharpcorner.com/Code/2002/Mar/CreatingDBProgrammaticallyMCB.asp
|||Sorry thats was for Windows Form try the link below for code from Microsoft.
http://support.microsoft.com/default.aspx?scid=kb;en-us;305079
|||Txh,
I've tried a similar excample and it did work for SQLServer. With SQLExpress I get an error, when opening the connection, something like "File not found".
What is the connection string for the SQLExpress? I replaces simple "Server=(local)" with "Server=.\\SQLEXPESS".
|||That code was talking about your server name, and the Master database that installs with every SQL Server. You are connecting to the Master database and file not found is not a valid error because the Master is always there. So try changing Express to your computer name. Hope this helps,|||Sorry, if my english is so bad.
I wrote, that I've tried this excample, slightly changed and that it did work for SQL Server, but not SQLExpress.
Changing the server name to ".\SQLEXPRESS" didn't help. May be, because SQLExpress has no master database.
So, how to change this sample code that it works with SQLExpress?
|||You cannot run SQL Server without the Master database, all your internal house keeping is done by the Master, I know I ran the Express in beta and it had a Master. And it must be your computer name and the Express for it to work YOUR_COMPUTER_NAME\SQLEXPRESS. Hope this helps.
Sunday, February 19, 2012
CreateSubscription Error
Later I tried to replace the fixed ExtensionParams array of the example with a call to the web service method GetExtensionSettings, where, for the desired delivery extension, a parameter array would first be dynamically filled with the required parameter names by the web service and then I would only have to supply the respective parameter values.
After that change, the call to the method CreateSubscription does not work, as it doesnt recognize a SendEmailToUserAlias=True parameter which is now also used for the call.
Why is that?Some properties returned by the GetExtensionSettings method are marked as
read-only and can not be passed back in during CreateSubscription calls.
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
"vsiat" <vsiat@.discussions.microsoft.com> wrote in message
news:853377AF-B0DC-477A-AD28-9507DC2559D8@.microsoft.com...
> I am trying to create an email subscription programmatically, so I first
followed the BOL example which worked ok.
> Later I tried to replace the fixed ExtensionParams array of the example
with a call to the web service method GetExtensionSettings, where, for the
desired delivery extension, a parameter array would first be dynamically
filled with the required parameter names by the web service and then I would
only have to supply the respective parameter values.
> After that change, the call to the method CreateSubscription does not
work, as it doesnt recognize a SendEmailToUserAlias=True parameter which is
now also used for the call.
> Why is that?
>