简体   繁体   中英

SQL Server Reporting Services Cannot Set Data Source Connection String

We have a number of SSRS sites serving reports to various locations. Each of these servers all have custom connections in each and every report (don't ask why, that's a tale too torrid to tell). Our goal is to replace all of these custom data sources with a single shared data source for all reports on each server.

To that end, I have created a C# program that will find each report on each server and point the current custom data sources to a currently existing shared data source. This executes and seems to work fine.

My next goal is to use C# to create the shared data source on each server where none currently exists.

My current dilemma arises here:

private static void CreateSharedDataSource(string user, string password, string connection) 
{
    DataSourceDefinition source = new DataSourceDefinition();

    source.CredentialRetrieval = CredentialRetrievalEnum.Store;
    source.ConnectString = connection;
    source.Enabled = true;
    source.EnabledSpecified = true;
    source.Extension = "SQL";
    source.ImpersonateUser = false;
    source.ImpersonateUserSpecified = false;
    source.Prompt = "Enter a user name and password to access the data source:";
    source.UserName = user;
    source.Password = password;
    source.WindowsCredentials = true;
    source.OriginalConnectStringExpressionBased = true;
    source.UseOriginalConnectString = true;

    try 
    {
        service.CreateDataSource("DbDataSource", "/DsFolder", false, source, null);
        Console.WriteLine("Data source created successfully");
    }
    catch (Exception e) 
    {
        Console.WriteLine(e.Message);
    }
}

The data source is created correctly and the user name and password are updated correctly. The problem is that, when I look at the newly created data source on the server, the Connect string property is empty and, yes, the correct value is being passed to it in the method above. If I plug that value into the shared source on the server and test the connection, it works fine, but I cannot get the C# program to update that value itself.

So, is there something subtle I'm missing? Am I misinterpreting a setting up there? Did I set a value wrong?

Clues appreciated.

I've never tried anything like this but a quick bit of research uncovered this which may be helpful.

https://docs.microsoft.com/en-us/dotnet/api/reportservice2010.datasourcedefinition.originalconnectstringexpressionbased?view=sqlserver-2016

It states

"Expression-based connection strings are not supported in shared data sources."

Assuming the conneciton string is just a plain text string then I would guess that you could set this to false. This may help preserve the string you pass in.

Alright, found my answer. I had a pre-existing data source that was working so, instead of creating it from scratch, I copied that and only changed the name. That created a data source where the Connect string did persist. Comparing the settings in that with what I was setting revealed:

source.UseOriginalConnectString = false;

whereas, my code was:

source.UseOriginalConnectString = true;

Looking that up in docs and it tells me "If true, the value of the ConnectString property is ignored."

Hmmm... that's intuitive. That's not what that sounds like at all. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM