Showing posts with label forms. Show all posts
Showing posts with label forms. Show all posts

Thursday, March 29, 2012

Changing Connection String programmatically

How can I change the Connection String programmatically?
(WS2005, Windows forms, C#)
I need to change the server name, or Initial Catalog parts of the string.
My connection strings are in a field of a master SQL database table.
The design of the different databases are the same.
How can I pass it to the _connection in the dataset?
_connection and InitConnection() are private.
I know, that I can edit the MyDbDataSet.Designer.cs, but I don't
belive, that it is good solution.
private void InitConnection() {
this._connection = new System.Data.SqlClient.SqlConnection();
this._connection.ConnectionString = "Data
Source=SQL\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security="
+
"True";
}
If the Data Source Confoguration Wizard saves the connection string,
the Settings.Designer.cs has also private properties I don't want edit.
Thanks - ZsoltSince if the SQL Server holding your connection strings is renamed or
changed, and you will not be able to get to the connection strings, that
seems like a bad idea.
Why not save the connection string(s) in the application.config file?
If you are storing connnection string information related to additional
servers, and you will use a confirmed static connection to retreive the
stored strings, just put them in a table. You may wish to have different
fields for server, database, security context, etc.. Create a stored
procedure that will provide you the concatenated string when you pass it a
parameter.
Arnie Rowland
"To be successful, your heart must accompany your knowledge."
"Zsolt" <Zsolt@.nowhere.nospam> wrote in message
news:1173DEA0-9696-4C12-8F58-ACA1926D85D8@.microsoft.com...
> How can I change the Connection String programmatically?
> (WS2005, Windows forms, C#)
> I need to change the server name, or Initial Catalog parts of the string.
> My connection strings are in a field of a master SQL database table.
> The design of the different databases are the same.
> How can I pass it to the _connection in the dataset?
> _connection and InitConnection() are private.
> I know, that I can edit the MyDbDataSet.Designer.cs, but I don't
> belive, that it is good solution.
> private void InitConnection() {
> this._connection = new System.Data.SqlClient.SqlConnection();
> this._connection.ConnectionString = "Data
> Source=SQL\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated
> Security=" +
> "True";
> }
> If the Data Source Confoguration Wizard saves the connection string,
> the Settings.Designer.cs has also private properties I don't want edit.
> Thanks - Zsolt
>|||Thank you for your answer, Arnie!
The reason for using different databases of the same design is that
every year we will create new database. After creating the new years
database, we will register it in the master database, entering the
necessary connection data in a table. DataSet should use any years
database, but only one at a time.
My problem is that how can I pass it to the DataSet, because it is
private. Of course I can edit the MyDataSet.Designer.cs file,
change the body of the private void InitConnection(), and it works:
private void InitConnection() {
this._connection = new System.Data.SqlClient.SqlConnection();
// insted of:
// this._connection.ConnectionString = "Data Source=SQL\\SQLEXPRESS;Initial
Catalog=Data2006;Integrated Security=True";
// This:
this._connection.ConnectionString = MyConnStrinProvider.GetConnString();
}
But whenever I make some changes on .xsd, the changes above are lost.
Changing of an <auto-generated> file seems not good.
I think there must be better solution then this.
Thank you again,
Zsolt
"Arnie Rowland" wrote:

> Since if the SQL Server holding your connection strings is renamed or
> changed, and you will not be able to get to the connection strings, that
> seems like a bad idea.
> Why not save the connection string(s) in the application.config file?
> If you are storing connnection string information related to additional
> servers, and you will use a confirmed static connection to retreive the
> stored strings, just put them in a table. You may wish to have different
> fields for server, database, security context, etc.. Create a stored
> procedure that will provide you the concatenated string when you pass it a
> parameter.
> --
> Arnie Rowland
> "To be successful, your heart must accompany your knowledge."
>
> "Zsolt" <Zsolt@.nowhere.nospam> wrote in message
> news:1173DEA0-9696-4C12-8F58-ACA1926D85D8@.microsoft.com...
>
>|||This is a good situation for putting the connection string information in th
e app.config file. You will not have to recompile and redeploy the applicati
on each year, only the app.config file.
Add an Application.config file to the solution, and then add the appSettings
section. You can add as many 'keys' as you wish. They are just name=value p
airs that the application can retrieve.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="DATA Source=ServerName;initial catalog=My
Database;integrated security=True" />
</appSettings>
</configuration>
Then in the application use:
for VB: Dim con As SqlConnection = New SqlConnection(System.Configuration.Co
nfigurationSettings.AppSettings("ConnectionString"))
for C#: SqlConnection con = New SqlConnection(System.Configuration.Configura
tionSettings.AppSettings("ConnectionString"))
You may wish to check further in VS Help about using an app.config file.
--
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Zsolt" <Zsolt@.nowhere.nospam> wrote in message news:DD87AECE-A6FF-4C8B-ABA6-B5B80B89D9A6@.mi
crosoft.com...[vbcol=seagreen]
> Thank you for your answer, Arnie!
>
> The reason for using different databases of the same design is that
> every year we will create new database. After creating the new years
> database, we will register it in the master database, entering the
> necessary connection data in a table. DataSet should use any years
> database, but only one at a time.
>
> My problem is that how can I pass it to the DataSet, because it is
> private. Of course I can edit the MyDataSet.Designer.cs file,
> change the body of the private void InitConnection(), and it works:
>
> private void InitConnection() {
> this._connection = new System.Data.SqlClient.SqlConnection();
> // insted of:
> // this._connection.ConnectionString = "Data Source=SQL\\SQLEXPRESS;Initi
al
> Catalog=Data2006;Integrated Security=True";
> // This:
> this._connection.ConnectionString = MyConnStrinProvider.GetConnString()
;
> }
>
> But whenever I make some changes on .xsd, the changes above are lost.
> Changing of an <auto-generated> file seems not good.
>
> I think there must be better solution then this.
>
> Thank you again,
> Zsolt
>
>
> "Arnie Rowland" wrote:
>|||Connection strings of different years (databases) can be stored in app.confi
g
file (among other places). User can select one, using a ComboBox. Ok.
Using the selected connect string, SqlConnection and SqlCommand can be
constructed, OK!
But DataTableAdapter's System.Data.SqlClient.SqlDataAdapter _adapter member
is declared in MyDataset.Designer.cs as private, so I can't access it. That
is my original problem.
Of course, I can edit the MyDataset.Designer.cs file, it compiles and works
well,
but it is not a clear method, and not recommended at all.
Any changes in MyDataset.xsd file overwrites my editing (program is under
construction).
That's why I am looking for better and clearer solution.
Thank you again,
--
Zsolt
"Arnie Rowland" wrote:
[vbcol=seagreen]
> This is a good situation for putting the connection string information in
the app.config file. You will not have to recompile and redeploy the applica
tion each year, only the app.config file.
> Add an Application.config file to the solution, and then add the appSettin
gs section. You can add as many 'keys' as you wish. They are just name=value
pairs that the application can retrieve.
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <appSettings>
> <add key="ConnectionString" value="DATA Source=ServerName;initial ca
talog=MyDatabase;integrated security=True" />
> </appSettings>
> </configuration>
> Then in the application use:
> for VB: Dim con As SqlConnection = New SqlConnection(System.Configuration.
ConfigurationSettings.AppSettings("ConnectionString"))
> for C#: SqlConnection con = New SqlConnection(System.Configuration.Configu
rationSettings.AppSettings("ConnectionString"))
> You may wish to check further in VS Help about using an app.config file.
> --
> Arnie Rowland
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "Zsolt" <Zsolt@.nowhere.nospam> wrote in message news:DD87AECE-A6FF-4C8B-AB
A6-B5B80B89D9A6@.microsoft.com...

Sunday, March 11, 2012

Change username

I'm using the Forms Authentication with Reporting Services, and I have a
situation where i need to change a username for a user. The user already has
lots permissions to different reports, etc... When I change the username in
my UserAccounts DB and the ReportServer DB it logs in fine, but shows no
objects.
When I view the reports via an admin account, it shows the security still
lists the old username, before I changed it.
Any ideas on how to successfully change a username in reporting services?
Thanks,
-Jonathan
Please post this to the SQL Server Reporting Services newsgroup:
reportingsvcs
Chris Skorlinski
Microsoft SQL Server Support
Please reply directly to the thread with any updates.
This posting is provided "as is" with no warranties and confers no rights.

Sunday, February 12, 2012

Change of namespace in forms authentication

I have implemented the forms based authentication by Teo Lachev and it works
fine. But whne I change the namespace to something else and make all the
necessay modifications in the config files , I just can get it to work. The
reportsmanager comes up with unable to communicate to the server!! Has
anyone attempted to do this Change the adventureworks.extensibility to
something else like myworks.extensibility'
Please let me know what do I have to do to get it working? Any help would
be most appreciated!!!There are a zillion dependencies when you change a namespace. We've done it
successfully, but I can't think of any way to debug it other than to do a
raw text search for the old name spaces in all your code files.
Make sure you stop and restart all of your services after the config
changes -- even reboot if you need to. There may be some changes that don't
get through. Also, are you updating all of your binaries?
Hope that helps,
'(' Jeff A. Stucker
\
Business Intelligence
www.criadvantage.com
---
"shahab" <shahab@.discussions.microsoft.com> wrote in message
news:6C056BE4-9E90-439C-8F1A-E248619C4EA5@.microsoft.com...
>I have implemented the forms based authentication by Teo Lachev and it
>works
> fine. But whne I change the namespace to something else and make all the
> necessay modifications in the config files , I just can get it to work.
> The
> reportsmanager comes up with unable to communicate to the server!! Has
> anyone attempted to do this Change the adventureworks.extensibility to
> something else like myworks.extensibility'
> Please let me know what do I have to do to get it working? Any help
> would
> be most appreciated!!!|||Thanks Jeff
I got it working, my problem was in the logon.aspx page as it could not load
the dll and I just overlooked ... silly me :-)
"Jeff A. Stucker" wrote:
> There are a zillion dependencies when you change a namespace. We've done it
> successfully, but I can't think of any way to debug it other than to do a
> raw text search for the old name spaces in all your code files.
> Make sure you stop and restart all of your services after the config
> changes -- even reboot if you need to. There may be some changes that don't
> get through. Also, are you updating all of your binaries?
> Hope that helps,
> '(' Jeff A. Stucker
> \
> Business Intelligence
> www.criadvantage.com
> ---
> "shahab" <shahab@.discussions.microsoft.com> wrote in message
> news:6C056BE4-9E90-439C-8F1A-E248619C4EA5@.microsoft.com...
> >I have implemented the forms based authentication by Teo Lachev and it
> >works
> > fine. But whne I change the namespace to something else and make all the
> > necessay modifications in the config files , I just can get it to work.
> > The
> > reportsmanager comes up with unable to communicate to the server!! Has
> > anyone attempted to do this Change the adventureworks.extensibility to
> > something else like myworks.extensibility'
> > Please let me know what do I have to do to get it working? Any help
> > would
> > be most appreciated!!!
>
>