Connection String for ADO Database in delphi prism

Hi,

I want to connect to a database with ADO and aspx.

from VB code what is the equivalent in delphi prism ?

....
Dim MyReader as sqldatareader
Dim MyConnection as sqlconnection = new sqlconnection()

myConnection.connectionstring = 
configurationmanager.connectionstrings("DSN_MYDB").connectionstring
Dim mycommand as sqlcommand = new sqlcommand()
mycommand.commandtext="select * from mytable"
mycommand.commandtype = commandtype.text
mycommand.connection = myconnection
mycommand.connection.open()
Myreader=mycommand.executereader(commandbehavior.closeconnection)

......

examples in Delphi Prism is welcome.

thanks
Alex
0
Alessandro
2/12/2010 6:36:27 PM
embarcadero.delphiprism.lang 246 articles. 0 followers. Follow

10 Replies
1044 Views

Similar Articles

[PageSpeed] 45

Le 12.02.2010 19:36, Alessandro Romano a écrit :
> Hi,
>
> I want to connect to a database with ADO and aspx.
>
> from VB code what is the equivalent in delphi prism ?
>
> ...
> Dim MyReader as sqldatareader
> Dim MyConnection as sqlconnection = new sqlconnection()
>
> myConnection.connectionstring =
> configurationmanager.connectionstrings("DSN_MYDB").connectionstring
> Dim mycommand as sqlcommand = new sqlcommand()
> mycommand.commandtext="select * from mytable"
> mycommand.commandtype = commandtype.text
> mycommand.connection = myconnection
> mycommand.connection.open()
> Myreader=mycommand.executereader(commandbehavior.closeconnection)
>
> .....
>
> examples in Delphi Prism is welcome.
>
> thanks
> Alex

Alex,

Var MyReader : SqlDataReader;
Var MyConnection := New SqlConnection (
                             ConnectionString := ConfigurationManager.ConnectionString 
('DSN_MYDB').ConnectionString;
Var MyCommand := New SqlCommand (
                        CommandText := 'Select * from mytable',
                        CommandType := CommandType.Text,
                        Connection  := MyConnection;
MyCommand.Connection.Open;
MyReader := MyCommand.ExecuteReader (CommandBehavior.CloseConnection);

Patrick
0
Patrick
2/12/2010 7:04:42 PM
thanks patrick,

i have test your code but i receive a error:
(i use delphi prism with access db)

--------------------------------------------------
  Var MyReader : SqlDataReader;
   Var MyConnection := New SqlConnection(ConnectionString := 
ConfigurationManager.ConnectionStrings('ergo')).ConnectionString;
   Var MyCommand := New SqlCommand (
                        CommandText := 'SELECT * FROM [TImmagini]',
                        CommandType := CommandType.Text,
                        Connection  := MyConnection);
       MyCommand.Connection.Open;
       MyReader := MyCommand.ExecuteReader 
(CommandBehavior.CloseConnection);


Compilation Error
Description: An error occurred during the compilation of a resource required 
to service this request.
Please review the following specific error details and modify your source 
code appropriately.

Compiler Error Message: PE215: (PE215) Cannot invoke non-delegate type 
"System.Configuration.ConnectionStringSettingsCollection"

Source Error:

Line 27: begin
Line 28:    Var MyReader : SqlDataReader;
Line 29:    Var MyConnection := New SqlConnection(ConnectionString := 
ConfigurationManager.ConnectionStrings('ergo')).ConnectionString;
Line 30:    Var MyCommand := New SqlCommand (
Line 31:    CommandText := 'SELECT * FROM [TImmagini]',

Source File: C:\Inetpub\wwwroot\ergosoft2010\prova2.aspx.pas    Line: 29
-------------------------------------------------------------------------------------------------

thanks

"Patrick Lanz" <chrome@ordinasoft.ch> ha scritto nel messaggio 
news:213442@forums.codegear.com...
> Le 12.02.2010 19:36, Alessandro Romano a écrit :
>> Hi,
>>
>> I want to connect to a database with ADO and aspx.
>>
>> from VB code what is the equivalent in delphi prism ?
>>
>> ...
>> Dim MyReader as sqldatareader
>> Dim MyConnection as sqlconnection = new sqlconnection()
>>
>> myConnection.connectionstring =
>> configurationmanager.connectionstrings("DSN_MYDB").connectionstring
>> Dim mycommand as sqlcommand = new sqlcommand()
>> mycommand.commandtext="select * from mytable"
>> mycommand.commandtype = commandtype.text
>> mycommand.connection = myconnection
>> mycommand.connection.open()
>> Myreader=mycommand.executereader(commandbehavior.closeconnection)
>>
>> .....
>>
>> examples in Delphi Prism is welcome.
>>
>> thanks
>> Alex
>
> Alex,
>
> Var MyReader : SqlDataReader;
> Var MyConnection := New SqlConnection (
>                             ConnectionString := 
> ConfigurationManager.ConnectionString
> ('DSN_MYDB').ConnectionString;
> Var MyCommand := New SqlCommand (
>                        CommandText := 'Select * from mytable',
>                        CommandType := CommandType.Text,
>                        Connection  := MyConnection;
> MyCommand.Connection.Open;
> MyReader := MyCommand.ExecuteReader (CommandBehavior.CloseConnection);
>
> Patrick
0
Alessandro
2/13/2010 10:06:25 AM
Give this a try:


Var MyConnection := New SqlConnection( connectionstring := ConfigurationManager.ConnectionStrings["ergo"].ToString);
0
Mark
2/13/2010 1:46:17 PM
Hi Mark,

no, NOT work

:(


<Mark Tiede> ha scritto nel messaggio news:213823@forums.codegear.com...
> Give this a try:
>
>
> Var MyConnection := New SqlConnection( connectionstring := 
> ConfigurationManager.ConnectionStrings["ergo"].ToString);
0
Alessandro
2/13/2010 4:05:35 PM
Hi Mark,

no, NOT work

:(


<Mark Tiede> ha scritto nel messaggio news:213823@forums.codegear.com...
> Give this a try:
>
>
> Var MyConnection := New SqlConnection( connectionstring := 
> ConfigurationManager.ConnectionStrings["ergo"].ToString);
0
Alessandro
2/13/2010 4:05:55 PM
Alessandro,
it should be:
Var MyConnection := New SqlConnection (ConnectionString :=
ConfigurationManager.ConnectionStrings ['ergo']).ConnectionString;
Because it's a collection.
Patrick

Le 13.02.2010 11:06, Alessandro Romano a écrit :
> thanks patrick,
>
> i have test your code but i receive a error:
> (i use delphi prism with access db)
>
> --------------------------------------------------
>    Var MyReader : SqlDataReader;
>     Var MyConnection := New SqlConnection(ConnectionString :=
> ConfigurationManager.ConnectionStrings('ergo')).ConnectionString;
>     Var MyCommand := New SqlCommand (
>                          CommandText := 'SELECT * FROM [TImmagini]',
>                          CommandType := CommandType.Text,
>                          Connection  := MyConnection);
>         MyCommand.Connection.Open;
>         MyReader := MyCommand.ExecuteReader
> (CommandBehavior.CloseConnection);
>
>
> Compilation Error
> Description: An error occurred during the compilation of a resource required
> to service this request.
> Please review the following specific error details and modify your source
> code appropriately.
>
> Compiler Error Message: PE215: (PE215) Cannot invoke non-delegate type
> "System.Configuration.ConnectionStringSettingsCollection"
>
> Source Error:
>
> Line 27: begin
> Line 28:    Var MyReader : SqlDataReader;
> Line 29:    Var MyConnection := New SqlConnection(ConnectionString :=
> ConfigurationManager.ConnectionStrings('ergo')).ConnectionString;
> Line 30:    Var MyCommand := New SqlCommand (
> Line 31:    CommandText := 'SELECT * FROM [TImmagini]',
>
> Source File: C:\Inetpub\wwwroot\ergosoft2010\prova2.aspx.pas    Line: 29
> -------------------------------------------------------------------------------------------------
>
> thanks
>
> "Patrick Lanz"<chrome@ordinasoft.ch>  ha scritto nel messaggio
> news:213442@forums.codegear.com...
>> Le 12.02.2010 19:36, Alessandro Romano a écrit :
>>> Hi,
>>>
>>> I want to connect to a database with ADO and aspx.
>>>
>>> from VB code what is the equivalent in delphi prism ?
>>>
>>> ...
>>> Dim MyReader as sqldatareader
>>> Dim MyConnection as sqlconnection = new sqlconnection()
>>>
>>> myConnection.connectionstring =
>>> configurationmanager.connectionstrings("DSN_MYDB").connectionstring
>>> Dim mycommand as sqlcommand = new sqlcommand()
>>> mycommand.commandtext="select * from mytable"
>>> mycommand.commandtype = commandtype.text
>>> mycommand.connection = myconnection
>>> mycommand.connection.open()
>>> Myreader=mycommand.executereader(commandbehavior.closeconnection)
>>>
>>> .....
>>>
>>> examples in Delphi Prism is welcome.
>>>
>>> thanks
>>> Alex
>>
>> Alex,
>>
>> Var MyReader : SqlDataReader;
>> Var MyConnection := New SqlConnection (
>>                              ConnectionString :=
>> ConfigurationManager.ConnectionString
>> ('DSN_MYDB').ConnectionString;
>> Var MyCommand := New SqlCommand (
>>                         CommandText := 'Select * from mytable',
>>                         CommandType := CommandType.Text,
>>                         Connection  := MyConnection;
>> MyCommand.Connection.Open;
>> MyReader := MyCommand.ExecuteReader (CommandBehavior.CloseConnection);
>>
>> Patrick
0
Patrick
2/13/2010 4:37:39 PM
> {quote:title=Patrick Lanz wrote:}{quote}
> Alessandro,
> it should be:
> Var MyConnection := New SqlConnection (ConnectionString :=
> ConfigurationManager.ConnectionStrings ['ergo']).ConnectionString;
> Because it's a collection.
> Patrick

I thought there was something like a collection there. Didn't actually test it.  Just got past compiler error :-)

The string above doesn't look right quite yet either.  Parentheses seem imbalanced.
0
Mark
2/14/2010 4:03:45 AM
Le 14.02.2010 05:03, Mark Tiede a écrit :
>> {quote:title=Patrick Lanz wrote:}{quote}
>> Alessandro,
>> it should be:
>> Var MyConnection := New SqlConnection (ConnectionString :=
>> ConfigurationManager.ConnectionStrings ['ergo']).ConnectionString;
>> Because it's a collection.
>> Patrick
>
> I thought there was something like a collection there. Didn't actually test it.  Just got past compiler error :-)
>
> The string above doesn't look right quite yet either.  Parentheses seem imbalanced.

Yes Mark, you're right:

Var MyConnection := New SqlConnection (
                           ConnectionString := ConfigurationManager.ConnectionStrings 
['ergo'].ConnectionString);

Should be correct now (I hope) :-))
Patrick
0
Patrick
2/14/2010 7:13:06 AM
Patrick,

no, NOT work,

the error is:
"object reference not set to an instance of an object"

Alex


"Patrick Lanz" <chrome@ordinasoft.ch> ha scritto nel messaggio 
news:214125@forums.codegear.com...
> Le 14.02.2010 05:03, Mark Tiede a écrit :
>>> {quote:title=Patrick Lanz wrote:}{quote}
>>> Alessandro,
>>> it should be:
>>> Var MyConnection := New SqlConnection (ConnectionString :=
>>> ConfigurationManager.ConnectionStrings ['ergo']).ConnectionString;
>>> Because it's a collection.
>>> Patrick
>>
>> I thought there was something like a collection there. Didn't actually 
>> test it.  Just got past compiler error :-)
>>
>> The string above doesn't look right quite yet either.  Parentheses seem 
>> imbalanced.
>
> Yes Mark, you're right:
>
> Var MyConnection := New SqlConnection (
>                           ConnectionString := 
> ConfigurationManager.ConnectionStrings
> ['ergo'].ConnectionString);
>
> Should be correct now (I hope) :-))
> Patrick
0
Alessandro
2/15/2010 7:41:24 AM
Le 15.02.2010 08:41, Alessandro Romano a écrit :
> Patrick,
>
> no, NOT work,
>
> the error is:
> "object reference not set to an instance of an object"
>
> Alex

Alex,
this is no more a language problem.
This is something you don't have initialized.
Your best bet is now to use the debugger to look at what's not initialized.
Patrick
0
Patrick
2/15/2010 9:23:01 AM
Reply:

Similar Artilces:

Connection string for Remote Database connectivity(SQL Server2000)
hai, I am working on ASP.NET 2003 with SQLServer2000. My application requires to be connected to the Database which is there in my Headoffice. My SQLServerName is "MyDBServer\TestDB" Database Name is "WebTO", UserID="******" and Password="******" My Remote Server IP Address is "192.168.1.2" and its Static IP is "58.93.61.235" I have specified the Connection string for my Remote Server as "Provider=SQLOLEDB.1;Server=58.93.61.235\TestDB;UID=******;PWD=******;Database=WebTO"        &...

ADO Connection to Excel; Connection String Changes After Disconnect?
I'm working on this new project in XE8 and trying to read data from an Excel xls spreadsheet (not an xlsx sheet). I'm still working on it in the IDE and I've noticed that when I get the connection string all setup (in the TADOConnection component), including the "Extended Properties=Excel 8.0" (that's required to connect) and I make Connected true and then make Connected false the connection string loses the extended properties that I manually entered. So if I try and connect again I get an error message "Unrecognized Database Format". I'm sure tha...

how i write connection string for database connectivity in hosting server
  HII am working with one ISp company and some asp.net applicationsrunning in our server,and one of the client complained his asp.net web application not working properly some of the pages not working. i think may be it is  for database connectivity problem if  this is problem , how i write connection string for database connectivity how i write   Check http://connectionstrings.com/Regards,Anas Ghanem.Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post t...

Database Connection???How to connect a Database in an other server?
How to connect a Database(.mdb) in an other server? Can I use the connection string like below? mycon.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=http://www.****.com/***/mydb.mdb" You can not. That simple. Access is file based. No a client/server architecture.Thomas TomiczekPowerNodes ApS(Microsoft MVP C#/.NET)---Building a Website? Try the PowerNodes CMS - http://www.powernodes.com/ Correction: you can. Just make sure you can reach the acces db file - through a file share that is bound as drive. Not that you should. Performance will be horrib...

Connect a DataSet to a database with a connection string defined outside of web.config
I believe this to be a fairly small issue in a fairly complex scenario; I'll do my best to explain. We have 2 solutions, and one is built using the other as a foundation.  In other words, one solution has all the functionality of the other, and then some other things added on.These 2 solutions need to connect to different databasesMany of the projects in the solutions, as well as the web.config file are "branched" between the two solutions.  Meaning that editing the web.config file in one solution will effect it in the other.To allow each solution to connect to a...

Database connection problem, perhaps an incorrect connection string? Please help!
Hi guys. I've put together this little bit of C# code to read a SQL Server 2005 database. However once the program compiles, the data does not load and populate the datagrid. I think that my connection string might be incorrect, but not sure. If anyone has any idea then I would be extremely grateful.  Heres the code.... using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlCont...

Database connection string
Hello, (I'm not sure if I chose the right forum group to post this issue. If not, please advise me as to what group I should post this instead, thanks) I currently define my connection string in the Web.config file under <appSettings>. This Web.config file is located in the root directory of the website. I need to set the connection string with different user ID's and passwords based on the user IP Address (currently, I'm not checking the IP Address and I'm using only one user ID and password for everyone). To do this, I need to check the IP Address and create a stri...

Database Connection String
Hello I wrote my first ASP.NET application a while ago for a university project, I now want to get the application working on an actual web server instead of my machine. I initially used the web.config file to set an application setting which stored the connection string for my database. Each page that needed to connect to the database could then retrieve this string from the web.config file and I would only have had to update this for different database locations or database types. The following is the key in the web.config file: <add key="ConnStr" value="Provi...

Database Connection String
I have a website that I want to password protect. I am using Dreamweaver. I have a SQL database. I know the name of the databse , but I do not know how to create the string. It's driving me crazy.I have already created an asp page and I tried to make a connection for 3 hours and i still haven't got it.Help!  http://connectionstrings.com/http://pavkata.blogspot.com/...

ADO Connection string
Does anyone know where there are any examples of connecting to an ASA db using an ADO _Connection object in C++? Thanks, -TC A quick search through this newsgroup would have resulted in the following find : cnADODB.ConnectionString = "Provider=ASAProv;LINKS=TCPIP();ENG=myDBEngine;DBN=myDBName;uid=DBA;pwd=SQL" -- Reg Domaratzki, Sybase iAnywhere Solutions Certified SQL Anywhere Associate Please reply only to the newsgroup ASA Patches and EBFs : http://downloads.sybase.com/swx/sdmain.stm -> Choose SQL Anywhere Studio -> Set "Platform ...

Database connection string
Ok I built a web system and for a company that I want to use in my portfolio. But I'm have some trouble getting the connection string for my local machine, also the format of the connection string for my local machine. Its a SQL server DB, how would I go about finding my connection string and what is syntax for the connection string in my asp page? Thanks in advance....

Problem getting connection from DataSource: java.lang.ClassCastException: java.lang.String
When trying to get a connection from a DataSource I get the following exception: java.lang.ClassCastException: java.lang.String I just upgraded to Jaguar/PowerJ 3.61 in the hopes to resolve this problem that I was having on 3.6, but it did not. I am running Jaguar on Sun Solaris. I created an EJB SessionBean and set up the DataSource in the "J2EE Resource References" in the Deploy tab of the EJB component. This exception goes away if I go into Jaguar Manager and define/re-setup the same DataSource with the same info there, then re-start Jaguar server. However,...

Database Connection Strings
My question is, are the user id and password optional when creating a database connection string? I've created an asp page without including them, but in my aspx page (which is basically supposed to do the exact same thing as the asp page), I'm receiving the following error: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: S...

Any difference between Delphi Prism 2011 and Delphi Prism XE?
Looking at the features in Delphi Prism XE, they look the same as the new items in the 2011 release back in may. I there anything new in the XE release? or did they simply change the product branding? Just wondering if I need to update it or now when i download the rest. Thanks, Hi Dan, > Looking at the features in Delphi Prism XE, they look the same as the new items in the 2011 release back in may. I there anything new in the XE release? or did they simply change the product branding? Just wondering if I need to update it or now when i download the rest. See http://w...

Web resources about - Connection String for ADO Database in delphi prism - embarcadero.delphiprism.lang

Connection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

iMedia Connection: Interactive Marketing News, Features, Podcasts and Video - iMediaConnection.com
If you send more email, you might make more money. Then again, you might destroy your reputation and revenue stream. Here's how to know what ...

HTTP persistent connection - Wikipedia, the free encyclopedia
... tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Following this, the connection ...

MOTHER’S DAY: Facebook Examines Connections Between Moms, Kids
With Mother’s Day on the calendar this coming Sunday, Facebook examined the relationships between mothers and their children on the social network, ...

Sydney's beauty relies on its visual and physical connection to nature
Landowners, custodians and developers must collaborate to create a healthy environment, happy residents and a more productive city.

Governor declares state of emergency in connection with California methane leak
... sites must now be monitored. On Wednesday evening, California Governor Jerry Brown declared a state of emergency in Los Angeles County in connection ...

Heavyset woman with facial hair arrested in connection to downto - CBS News 8 - San Diego, CA News Station ...
Police were on the lookout Thursday for a heavyset woman with facial hair who stabbed a man in the East Village.

10th person arrested in connection with Paris attacks
CNN 10th person arrested in connection with Paris attacks CNN (CNN) Belgian police have arrested a 10th person in connection with last month's ...

Should auld connections be forgot...
This environmental testing company has strict data-retention requirements and they go beyond the data, reports a pilot fish on the scene. "Per ...

Test Claims To Show T-Mobile’s YouTube “Optimization” Is Just Connection Throttling
... on the same network, and at the same time of day. They tested video streaming against three other kinds of downloads and measured the connection ...

Resources last updated: 1/8/2016 7:38:57 PM