Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, July 4, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: DB connection from SmartPart
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 8:37 AM
I am running some code from a smart part that requires connecting to the DB. Currently I am using this method:
SqlConnection myConnection = new SqlConnection("Data Source=WIN2KVANILLA\\SQLEXPRESS;Initial Catalog=Saleslogix_Eval;User Id=sysdbaassword=masterkey;");

If there a way I can open the connection without hardcoding the connection string, so when I move to production I don't have to change the connection string? I seem to recall someone at the dev class mentioning this, but cannot remember the details. Thanks
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 9:31 AM
Sage.Platform.Data.IDataService service = 
Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IDataService>();

string connstring = service.GetConnectionString();


-Ryan
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 9:51 AM
Oops. It ate my angle brackets. I've fixed that in the post.
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 10:05 AM
Solid Gold! I am getting this error - I must need a reference..
The type or namespace name 'IDataService' does not exist in the namespace 'Sage.Platform.Security' (are you missing an assembly reference?)

I tried adding this and got this error:
@ Register Assembly="Sage.Platform.Security" Namespace="Sage.Platform.Security.IDataService" TagPrefix="SalesLogix"

Could not load file or assembly 'Sage.Platform.Security' or one of its dependencies. The system cannot find the file specified.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 10:59 AM
Oops. That is my fault. I was typing it from memory before and some wires got crossed

Here's what it is *supposed* to be:

Sage.Platform.Data.IDataService service = 
ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();

string connstring = service.GetConnectionString();


IDataService is "Sage.Platform.Data.IDataService", not "Sage.Platform.Security.IDataService". Doh! Sorry about that (but at least I typed it right the first time in that post ).

-Ryan
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 11:01 AM
Stupid angle brackets! Fixed those again.
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 11:09 AM
Almost? I now get this error (starting to feel like a pest.. sorry about that):
error CS0103: The name 'ApplicationContext' does not exist in the current context
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 11:31 AM
Ok, I am by the 'ApplicatonContext' error but am having another problem..

Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string myConnection = service.GetConnectionString();
myConnection.Open();

I am unsure of how to open the connection.. I am getting this error with the above code:
'string' does not contain a definition for 'Open'
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Mar 08 11:51 AM
The GetConnectionString() returns just that, a connection *string*. You'll need to create a connection and use that string to open.

Something like this:

Sage.Platform.Data.IDataService service =       
Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();

System.Data.OleDbConnection conn = new System.Data.OleDbConnection(service.GetConnectionString());
conn.Open();
//...


Make sense?

BTW, no, you're not being a pest. This is what the forums are for!
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Mar 08 6:21 AM
Hey Steve,

The IDataService can provide either a Connection or a Connection String. I believe that the GetConnection method returns an IDbConnection object so it is also possible to;

Sage.Platform.Data.IDataService service = .....
using(IDbConnection conn = service.GetConnection()) {
conn.Open();

IDbCommand command = conn.CreateConnection();
command.CommandText = "Update ..... ";
command.Execute......;

}

- Mark
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Mar 08 9:44 AM
Gentlemen, A million thanks. Here is what I finally went with:

Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
IDbConnection myConnection = service.GetConnection();
myConnection.Open();
IDbCommand MyCommand = myConnection.CreateCommand();
MyCommand.CommandText = "select Email from Contact where accountID='AGHEA0002669'";
IDataReader MyDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
[Reply][Quote]
Nicolas Galler
Posts: 93
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Mar 08 12:08 PM
Btw... speaking from a painful experience... don't forget to make absolutely sure your data reader gets closed... something like this:

using(IDataReader MyDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)){
// code here
}

Otherwise it will bite you hard 2 hours after you push it to production.
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Mar 08 1:43 PM
Thanks for the advice Nicolas. I implemented in my code. New to C# and rusty on ASP.net so I really appreciate the tips.
[Reply][Quote]
Veronka Capone
Posts: 113
 
Re: DB connection from SmartPartYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 09 9:49 AM
Hi Ryan,

I am on 7.52 Web Client trying to create a BizRule using OleDBConnection.

I get following error when trying to get the OleDBConnection or IDbConnection The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

???

Any idea why?

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 7/4/2025 8:05:38 AM