Wednesday, March 28, 2012
Openning an access database using ADO.NET
I have the following code, but somehow it does not compile saying that it doesn't find the mdb file called PhoneBook :
OleDbConnection Myconnection = null;
Myconnection = new OleDbConnection(@."Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\PhoneBook");
Myconnection.Open();
What am I doing wrong here ?
All help appreciated !:)Stab in the dark:
change C:\PhoneBook to include the file extension i.e. C:\PhoneBook.mdb|||http://www.connectionstrings.comsql
Opening SqlConnection - VB.NET
"DSN=[data source name];UID=[sql server user];PWD=[pwd]"
I don't understand the connect string given in all the examples I've found (nor does it seem to work on my system...)
mySqlConnection =New SqlConnection("server=(local)\VSdotNET;Trusted_Connection=yes;database=northwind")
Does anyone have any ideas? I'm open to explanations as well as solutions :)
Thanks,
jdm
Can you shell out to DOS (EDIT: i.e. acommand prompt, sheesh my age is showing), and run this command:
osql -L
This will tell you the name of the SQL Servers to which you haveaccess. Whatever is returned is what should go into the server=part of the connection string. If you are still having trouble,please paste your connection string and error message and we will tryto help you through it.
|||
Success! The thing is that I don't want to specify a server name but rather a System DSN... So I think based on a little more research (thanks connectionstrings.com), I don't want to use a sqlConnection but an odbcConnection. Here is my latest attempt:
Dim myOdbcConnectionAs OdbcConnection
Dim myOdbcCommandAs OdbcCommand
Dim myOdbcDataReaderAs OdbcDataReader
myOdbcConnection =New OdbcConnection("DSN=DSN;User Id=sa;Password=PWD")
myodbccommand =New OdbcCommand(SQLString, myOdbcConnection)
myOdbcConnection.Open()
myOdbcDataReader = myOdbcCommand.ExecuteReader(CommandBehavior.CloseConnection)
The program breaks on the myOdbcConnection.Open line, with an error
ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
So if I add "Trusted_Connection=true" to the connect string everything seems to work out. At this point, my question is what does the trusted connection variable really mean? Am I making a security mistake?
I'm new to this so any comments welcome.
Thanks!
jdm
Monday, March 26, 2012
Opening Report Server 2005 web site with VS 2005
2.0" when I open the report server web site using VS 2005. This is on
Windows 2003 and the SSRS 2005. Any idea how I can resolve this?
Thanks,
GilgameshWhat do you mean by this? You don't open up a report server web site in VS.
There is no way to do that. Do you mean you open up a project that has
reports? Or that you try to deploy to the server. You never directly touch
RS website. You install it, you deploy to it. You open up the portal. But
you never open up in VS.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Gilgamesh" <gilgamesh4ever@.aol.com> wrote in message
news:OEtDx9P4HHA.4712@.TK2MSFTNGP04.phx.gbl...
> I'm getting the "Report Server has not been congured for use with ASP.NET
> 2.0" when I open the report server web site using VS 2005. This is on
> Windows 2003 and the SSRS 2005. Any idea how I can resolve this?
> Thanks,
> Gilgamesh
>|||Well, report server is an asp.net applciation, and I was able to open the
web site using VS 2005. I'm working on the security extension which reuires
making changes to the logon.aspx page, and also I would need to create a new
aspx page and add the report viewer to it. The problem is that I can't even
open the site successuly.
-G
"Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> wrote in message
news:ewScpJQ4HHA.4476@.TK2MSFTNGP06.phx.gbl...
> What do you mean by this? You don't open up a report server web site in
> VS. There is no way to do that. Do you mean you open up a project that has
> reports? Or that you try to deploy to the server. You never directly touch
> RS website. You install it, you deploy to it. You open up the portal. But
> you never open up in VS.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Gilgamesh" <gilgamesh4ever@.aol.com> wrote in message
> news:OEtDx9P4HHA.4712@.TK2MSFTNGP04.phx.gbl...
>> I'm getting the "Report Server has not been congured for use with ASP.NET
>> 2.0" when I open the report server web site using VS 2005. This is on
>> Windows 2003 and the SSRS 2005. Any idea how I can resolve this?
>> Thanks,
>> Gilgamesh
>|||I have not implemented forms security (which is what I assume you are doing)
but reading up on it, it does not seem to me you are modifying anything
other than config files for RS. Yes RS is an asp.net application but I am
pretty sure that you do not modify it directly. You create your own asp.net
application that has your logon form and you modify config files with RS
2005.
Now on the off chance I am completely wrong about this and the reality is
that you do have to do as you are suggesting, are you sure this is RS 2005?
RS 2000 is a 1.1 framework application rather than a 2.0 framework app like
RS 2005.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Gilgamesh" <gilgamesh4ever@.aol.com> wrote in message
news:OjzehOQ4HHA.3684@.TK2MSFTNGP02.phx.gbl...
> Well, report server is an asp.net applciation, and I was able to open the
> web site using VS 2005. I'm working on the security extension which
> reuires making changes to the logon.aspx page, and also I would need to
> create a new aspx page and add the report viewer to it. The problem is
> that I can't even open the site successuly.
> -G
>
> "Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> wrote in message
> news:ewScpJQ4HHA.4476@.TK2MSFTNGP06.phx.gbl...
>> What do you mean by this? You don't open up a report server web site in
>> VS. There is no way to do that. Do you mean you open up a project that
>> has reports? Or that you try to deploy to the server. You never directly
>> touch RS website. You install it, you deploy to it. You open up the
>> portal. But you never open up in VS.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Gilgamesh" <gilgamesh4ever@.aol.com> wrote in message
>> news:OEtDx9P4HHA.4712@.TK2MSFTNGP04.phx.gbl...
>> I'm getting the "Report Server has not been congured for use with
>> ASP.NET 2.0" when I open the report server web site using VS 2005. This
>> is on Windows 2003 and the SSRS 2005. Any idea how I can resolve this?
>> Thanks,
>> Gilgamesh
>>
>
Opening report in new window
soon as the the report is opened, asp.net post-backs will fail.
This is what I do:
window.open('http//:[ip address]/reportserver?/ReportFolder/
ReportName')
As soon as I do that, asp.net post-backs on the opener will 'do
nothing'.
strange thing is that if I open the report using the name of the
server rather than ip address, it works fine
window.open('http//:[server name]/reportserver?/ReportFolder/
ReportName')
it also works fine on a development machine using 'localhost'.
The behavior I describe happens when the application is deployed to a
production server. Our customer must use the ip address of the server
for various reasons.
I've tried using a relative url ('../../reportserver?...') and i get
the same behaviour.
Any ideas?Have you tried using Globals!ReportServerUrl
"ruben@.lindenservices.com" wrote:
> I have a problem when opening a sql 2000 report in a new window. As
> soon as the the report is opened, asp.net post-backs will fail.
> This is what I do:
> window.open('http//:[ip address]/reportserver?/ReportFolder/
> ReportName')
> As soon as I do that, asp.net post-backs on the opener will 'do
> nothing'.
> strange thing is that if I open the report using the name of the
> server rather than ip address, it works fine
> window.open('http//:[server name]/reportserver?/ReportFolder/
> ReportName')
> it also works fine on a development machine using 'localhost'.
> The behavior I describe happens when the application is deployed to a
> production server. Our customer must use the ip address of the server
> for various reasons.
> I've tried using a relative url ('../../reportserver?...') and i get
> the same behaviour.
> Any ideas?
>sql
Opening local XML file
I want to open a local XML file from my SQL script.
#1. If you are in some dev't environment such as .Net or script, you can
open the file and pass it into the SQL script. But I want that within SQL
script.
#2. You can write a CLR function to open it. I did. However I feel like pay
too much for such a trivial job.
#3. I found a way to retrieve a file as base64 string. e.g.,
declare @.b varbinary(max)
set @.b=(select * from openrowset(bulk N'c:\x.xml', single_blob) as b)
That looks like decent base64 binary text which can be converted into XML
stream easily, if you are in .Net. But how do you do that within SQL script?
Or is there another way #4, #5, ... I have not imagined?
#2 UDF
public static SqlXml getdoc(string xmlPath)
{
XmlReader xr = XmlReader.Create(xmlPath);
SqlXml retSqlXml = new SqlXml(xr);
xr.Close();
return (retSqlXml);
}
Pohwan Han. Seoul. Have a nice day.declare @.b xml
set @.b=(select * from openrowset(bulk N'c:\x.xml', single_blob) as b)
SELECT @.b
VARBINARY can be implicitly converted to xml, assuming the stream actually
is xml.
Dan
> declare @.b varbinary(max)
> set @.b=(select * from openrowset(bulk N'c:\x.xml', single_blob) as b)|||Thanks Dan.
It worked.
Pohwan Han. Seoul. Have a nice day.
"Dan Sullivan" <danATpluralsight.com> wrote in message
news:964a9ae6140488c868bbaa3f4180@.news.microsoft.com...
> declare @.b xml
> set @.b=(select * from openrowset(bulk N'c:\x.xml', single_blob) as b)
> SELECT @.b
> VARBINARY can be implicitly converted to xml, assuming the stream actually
> is xml.
> Dan
>
>sql
Monday, March 12, 2012
Open Connections - Can't Drop
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
I have no problems Dropping the Tables.
Thanks,
Chuck
Where is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
|||Hello Thank You for you help.
I have the Stored Procedure inside the Master Table.
I am immediately running the query given after connecting. I also cannot
remove it from SQL Express Management Studio. - That is if I copy the SQL
into a query window and run it. I get the exact same error.
Chuck
"Hardik Bati" <hardikb_removethis_@.microsoft.com> wrote in message
news:OLkzPow9GHA.4376@.TK2MSFTNGP03.phx.gbl...
Where is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
|||Hello,
I have been doing some testing. I am filling a Dataset using a DataAdapter.
If I create a new connection to SQL Express without calling the
DataAdapter's Fill Method I can Drop the Database.
If I Fill the Dataset with the DataAdapter, dispose the connection and the
DataAdapter and create a new connection it still wont Drop the Database.
Even if the Dataset is empty it still does not work. It appears that
calling the DataAdapter before dropping the table keeps the database in use
weather it has finished it's job or not.
I can't even call a Stored Procedure to drop the Database if I call the
DataAdapter First. Even if I run the program and call the DataAdapter and
go into SQL Express Management Studio, I still get the same error. Only
when I shut down the program or drop the table without using the DataAdapter
does it work.
Is there a way around this?
Thanks
Chuck
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
Hello,
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
I have no problems Dropping the Tables.
Thanks,
Chuck
|||The most likely cause is that the closed/disposed connection is pooled and
the pooled connection is preventing you from dropping the database. You can
specify Pooling=False in the connection string (or similar, depending on the
provider you are using) to disable connection pooling.
Another method is to execute "ALTER DATABASE MyDatabase SET SINGLE_USER WITH
ROLLBACK IMMEDIATE" to kill all connections to the database befor the drop.
Hope this helps.
Dan Guzman
SQL Server MVP
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:OgZmXqz9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I have been doing some testing. I am filling a Dataset using a
> DataAdapter.
> If I create a new connection to SQL Express without calling the
> DataAdapter's Fill Method I can Drop the Database.
> If I Fill the Dataset with the DataAdapter, dispose the connection and the
> DataAdapter and create a new connection it still wont Drop the Database.
> Even if the Dataset is empty it still does not work. It appears that
> calling the DataAdapter before dropping the table keeps the database in
> use
> weather it has finished it's job or not.
> I can't even call a Stored Procedure to drop the Database if I call the
> DataAdapter First. Even if I run the program and call the DataAdapter and
> go into SQL Express Management Studio, I still get the same error. Only
> when I shut down the program or drop the table without using the
> DataAdapter
> does it work.
> Is there a way around this?
> Thanks
> Chuck
>
> "Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
> news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
Open Connections - Can't Drop
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
I have no problems Dropping the Tables.
Thanks,
ChuckWhere is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>|||Hello Thank You for you help.
I have the Stored Procedure inside the Master Table.
I am immediately running the query given after connecting. I also cannot
remove it from SQL Express Management Studio. - That is if I copy the SQL
into a query window and run it. I get the exact same error.
Chuck
"Hardik Bati" <hardikb_removethis_@.microsoft.com> wrote in message
news:OLkzPow9GHA.4376@.TK2MSFTNGP03.phx.gbl...
Where is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>|||Hello,
I have been doing some testing. I am filling a Dataset using a DataAdapter.
If I create a new connection to SQL Express without calling the
DataAdapter's Fill Method I can Drop the Database.
If I Fill the Dataset with the DataAdapter, dispose the connection and the
DataAdapter and create a new connection it still wont Drop the Database.
Even if the Dataset is empty it still does not work. It appears that
calling the DataAdapter before dropping the table keeps the database in use
weather it has finished it's job or not.
I can't even call a Stored Procedure to drop the Database if I call the
DataAdapter First. Even if I run the program and call the DataAdapter and
go into SQL Express Management Studio, I still get the same error. Only
when I shut down the program or drop the table without using the DataAdapter
does it work.
Is there a way around this?
Thanks
Chuck
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
Hello,
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
I have no problems Dropping the Tables.
Thanks,
Chuck|||The most likely cause is that the closed/disposed connection is pooled and
the pooled connection is preventing you from dropping the database. You can
specify Pooling=False in the connection string (or similar, depending on the
provider you are using) to disable connection pooling.
Another method is to execute "ALTER DATABASE MyDatabase SET SINGLE_USER WITH
ROLLBACK IMMEDIATE" to kill all connections to the database befor the drop.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:OgZmXqz9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I have been doing some testing. I am filling a Dataset using a
> DataAdapter.
> If I create a new connection to SQL Express without calling the
> DataAdapter's Fill Method I can Drop the Database.
> If I Fill the Dataset with the DataAdapter, dispose the connection and the
> DataAdapter and create a new connection it still wont Drop the Database.
> Even if the Dataset is empty it still does not work. It appears that
> calling the DataAdapter before dropping the table keeps the database in
> use
> weather it has finished it's job or not.
> I can't even call a Stored Procedure to drop the Database if I call the
> DataAdapter First. Even if I run the program and call the DataAdapter and
> go into SQL Express Management Studio, I still get the same error. Only
> when I shut down the program or drop the table without using the
> DataAdapter
> does it work.
> Is there a way around this?
> Thanks
> Chuck
>
> "Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
> news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
Open Connections - Can't Drop
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
I have no problems Dropping the Tables.
Thanks,
Chuck
Where is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
|||Hello Thank You for you help.
I have the Stored Procedure inside the Master Table.
I am immediately running the query given after connecting. I also cannot
remove it from SQL Express Management Studio. - That is if I copy the SQL
into a query window and run it. I get the exact same error.
Chuck
"Hardik Bati" <hardikb_removethis_@.microsoft.com> wrote in message
news:OLkzPow9GHA.4376@.TK2MSFTNGP03.phx.gbl...
Where is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
|||Hello,
I have been doing some testing. I am filling a Dataset using a DataAdapter.
If I create a new connection to SQL Express without calling the
DataAdapter's Fill Method I can Drop the Database.
If I Fill the Dataset with the DataAdapter, dispose the connection and the
DataAdapter and create a new connection it still wont Drop the Database.
Even if the Dataset is empty it still does not work. It appears that
calling the DataAdapter before dropping the table keeps the database in use
weather it has finished it's job or not.
I can't even call a Stored Procedure to drop the Database if I call the
DataAdapter First. Even if I run the program and call the DataAdapter and
go into SQL Express Management Studio, I still get the same error. Only
when I shut down the program or drop the table without using the DataAdapter
does it work.
Is there a way around this?
Thanks
Chuck
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
Hello,
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
I have no problems Dropping the Tables.
Thanks,
Chuck
|||The most likely cause is that the closed/disposed connection is pooled and
the pooled connection is preventing you from dropping the database. You can
specify Pooling=False in the connection string (or similar, depending on the
provider you are using) to disable connection pooling.
Another method is to execute "ALTER DATABASE MyDatabase SET SINGLE_USER WITH
ROLLBACK IMMEDIATE" to kill all connections to the database befor the drop.
Hope this helps.
Dan Guzman
SQL Server MVP
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:OgZmXqz9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I have been doing some testing. I am filling a Dataset using a
> DataAdapter.
> If I create a new connection to SQL Express without calling the
> DataAdapter's Fill Method I can Drop the Database.
> If I Fill the Dataset with the DataAdapter, dispose the connection and the
> DataAdapter and create a new connection it still wont Drop the Database.
> Even if the Dataset is empty it still does not work. It appears that
> calling the DataAdapter before dropping the table keeps the database in
> use
> weather it has finished it's job or not.
> I can't even call a Stored Procedure to drop the Database if I call the
> DataAdapter First. Even if I run the program and call the DataAdapter and
> go into SQL Express Management Studio, I still get the same error. Only
> when I shut down the program or drop the table without using the
> DataAdapter
> does it work.
> Is there a way around this?
> Thanks
> Chuck
>
> "Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
> news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuer y()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
Open Connections - Can't Drop
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
I have no problems Dropping the Tables.
Thanks,
ChuckWhere is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>|||Hello Thank You for you help.
I have the Stored Procedure inside the Master Table.
I am immediately running the query given after connecting. I also cannot
remove it from SQL Express Management Studio. - That is if I copy the SQL
into a query window and run it. I get the exact same error.
Chuck
"Hardik Bati" <hardikb_removethis_@.microsoft.com> wrote in message
news:OLkzPow9GHA.4376@.TK2MSFTNGP03.phx.gbl...
Where is this stored procedure. If it's in the database then you won't be
able to use it to drop the database while you are in the same database.
Are you trying to run the query directly after connecting useing the
connection string just given. Or is there any "use Customer" before execute
ExecuteNonQuery().
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>|||Hello,
I have been doing some testing. I am filling a Dataset using a DataAdapter.
If I create a new connection to SQL Express without calling the
DataAdapter's Fill Method I can Drop the Database.
If I Fill the Dataset with the DataAdapter, dispose the connection and the
DataAdapter and create a new connection it still wont Drop the Database.
Even if the Dataset is empty it still does not work. It appears that
calling the DataAdapter before dropping the table keeps the database in use
weather it has finished it's job or not.
I can't even call a Stored Procedure to drop the Database if I call the
DataAdapter First. Even if I run the program and call the DataAdapter and
go into SQL Express Management Studio, I still get the same error. Only
when I shut down the program or drop the table without using the DataAdapter
does it work.
Is there a way around this?
Thanks
Chuck
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
Hello,
I am using SQL Express and Visual Studion 2003. I am trying to DROP
DATABASE Customers using a Stored Procedure and also using ADO.NET.
Query:
IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
DATABASE [Customers]
ConnectionString:
RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
Password=MyPassword;Initial Catalog=master"
Everytime I call the procedure or ExecuteNonQuery I get:
Cannot Drop Database 'Customers' because database is currently in use. by
sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
I have no problems Dropping the Tables.
Thanks,
Chuck|||The most likely cause is that the closed/disposed connection is pooled and
the pooled connection is preventing you from dropping the database. You can
specify Pooling=False in the connection string (or similar, depending on the
provider you are using) to disable connection pooling.
Another method is to execute "ALTER DATABASE MyDatabase SET SINGLE_USER WITH
ROLLBACK IMMEDIATE" to kill all connections to the database befor the drop.
Hope this helps.
Dan Guzman
SQL Server MVP
"Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
news:OgZmXqz9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I have been doing some testing. I am filling a Dataset using a
> DataAdapter.
> If I create a new connection to SQL Express without calling the
> DataAdapter's Fill Method I can Drop the Database.
> If I Fill the Dataset with the DataAdapter, dispose the connection and the
> DataAdapter and create a new connection it still wont Drop the Database.
> Even if the Dataset is empty it still does not work. It appears that
> calling the DataAdapter before dropping the table keeps the database in
> use
> weather it has finished it's job or not.
> I can't even call a Stored Procedure to drop the Database if I call the
> DataAdapter First. Even if I run the program and call the DataAdapter and
> go into SQL Express Management Studio, I still get the same error. Only
> when I shut down the program or drop the table without using the
> DataAdapter
> does it work.
> Is there a way around this?
> Thanks
> Chuck
>
> "Charles A. Lackman" <Charles@.CreateItSoftware.net> wrote in message
> news:epQ433v9GHA.1172@.TK2MSFTNGP03.phx.gbl...
> Hello,
> I am using SQL Express and Visual Studion 2003. I am trying to DROP
> DATABASE Customers using a Stored Procedure and also using ADO.NET.
> Query:
> IF EXISTS (SELECT name FROM sys.databases WHERE name = Customers) DROP
> DATABASE [Customers]
> ConnectionString:
> RemoveConnectionString = "Server = MyComputer\SQLExpress;UID=sa;
> Password=MyPassword;Initial Catalog=master"
>
> Everytime I call the procedure or ExecuteNonQuery I get:
> Cannot Drop Database 'Customers' because database is currently in use. by
> sqlclient.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> I have no problems Dropping the Tables.
> Thanks,
> Chuck
>
>
Friday, March 9, 2012
Open .RDL in ASP.NET without ReportServer
report dynamically without any report url or anything.
I just want to pass the database authentication to the .RDL [reportViewer?]
and a few parameters, and run the report. But I do not want the report to
exist in a subweb or http://reportServer etc. I just want to drop it right
into my project, and go.
Thanks for any links or advice.This is totally possible with the new controls that ship with VS 2005. You
can develop the report and then view it in your app using the controls. Note
that this is more work. You have to handle subreports, drill through etc.
Also, I found the design environment in VS 2005 that comes with VS to design
reports nowhere as near as nice as the report designer that comes with SQL
Server. Note that if you have SQL Server, the designer comes with it. You
can develop and preview the reports without deploying them, then just change
the extension and bring them into your project.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Chris" <cmill575@.hotmail.com> wrote in message
news:u5QFgtdBGHA.3604@.TK2MSFTNGP09.phx.gbl...
> Is it possible to simply add an .RDL to an asp.net project, and access the
> report dynamically without any report url or anything.
> I just want to pass the database authentication to the .RDL
> [reportViewer?] and a few parameters, and run the report. But I do not
> want the report to exist in a subweb or http://reportServer etc. I just
> want to drop it right into my project, and go.
> Thanks for any links or advice.
>|||Thanks for your response. That's good news. I hope MS improves the designer
in VS.
Cant you just design the report using the SQL Server report designer and
then drop the rdl into your web project?
Anyway, thanks again.
BTW: Does anyone have any walkthrough's using this new functionality? I
havent used RS since it first came out.
"Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> wrote in message
news:u1R684jBGHA.3292@.TK2MSFTNGP09.phx.gbl...
> This is totally possible with the new controls that ship with VS 2005. You
> can develop the report and then view it in your app using the controls.
> Note that this is more work. You have to handle subreports, drill through
> etc. Also, I found the design environment in VS 2005 that comes with VS to
> design reports nowhere as near as nice as the report designer that comes
> with SQL Server. Note that if you have SQL Server, the designer comes with
> it. You can develop and preview the reports without deploying them, then
> just change the extension and bring them into your project.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Chris" <cmill575@.hotmail.com> wrote in message
> news:u5QFgtdBGHA.3604@.TK2MSFTNGP09.phx.gbl...
>> Is it possible to simply add an .RDL to an asp.net project, and access
>> the report dynamically without any report url or anything.
>> I just want to pass the database authentication to the .RDL
>> [reportViewer?] and a few parameters, and run the report. But I do not
>> want the report to exist in a subweb or http://reportServer etc. I just
>> want to drop it right into my project, and go.
>> Thanks for any links or advice.
>|||You can use the SQL Server report designer and then rename the extension and
then use that. That is really the easiest. The issue with VS is that there
is no preview. You have to deploy and use either your web page or your
winform to view the report.
Just dropping the rdl into your web project makes no sense unless there is
something to render the report. That is where the new controls come in.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Chris" <cmill575@.hotmail.com> wrote in message
news:%23Xt1UVpBGHA.2300@.TK2MSFTNGP15.phx.gbl...
> Thanks for your response. That's good news. I hope MS improves the
> designer in VS.
> Cant you just design the report using the SQL Server report designer and
> then drop the rdl into your web project?
> Anyway, thanks again.
> BTW: Does anyone have any walkthrough's using this new functionality? I
> havent used RS since it first came out.
>
> "Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> wrote in message
> news:u1R684jBGHA.3292@.TK2MSFTNGP09.phx.gbl...
>> This is totally possible with the new controls that ship with VS 2005.
>> You can develop the report and then view it in your app using the
>> controls. Note that this is more work. You have to handle subreports,
>> drill through etc. Also, I found the design environment in VS 2005 that
>> comes with VS to design reports nowhere as near as nice as the report
>> designer that comes with SQL Server. Note that if you have SQL Server,
>> the designer comes with it. You can develop and preview the reports
>> without deploying them, then just change the extension and bring them
>> into your project.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Chris" <cmill575@.hotmail.com> wrote in message
>> news:u5QFgtdBGHA.3604@.TK2MSFTNGP09.phx.gbl...
>> Is it possible to simply add an .RDL to an asp.net project, and access
>> the report dynamically without any report url or anything.
>> I just want to pass the database authentication to the .RDL
>> [reportViewer?] and a few parameters, and run the report. But I do not
>> want the report to exist in a subweb or http://reportServer etc. I just
>> want to drop it right into my project, and go.
>> Thanks for any links or advice.
>>
>
Monday, February 20, 2012
Online query to my database
queries to my database over the net by a GUI developed in Visual Studio .NET.
Could someone explain the procedure I must follow to accomplish such an aim.
I mean that database is in the desktop computer in my house and I want to
make query from my friend's desktop computer which is somewhere else. Hence,
I need something that should be performed over the net.
Thanls in advance
Hi ,
Please go through the following piece of information which will be useful
in your case.
ADO can use any OLE DB provider to establish a connection. The provider is
specified through the Provider property of the Connection object.
Microsoft SQL Server 2000 applications use SQLOLEDB to connect to an
instance of SQL Server, although existing applications can also use MSDASQL
to maintain backward compatibility.
Using the Execute method of the Connection object is one way to execute an
SQL statement against a SQL Server data source.
The Connection object allows you to:
Configure a connection.
Establish and terminate sessions with data sources.
Identify an OLE DB provider.
Execute a query.
Manage transactions on the open connection.
Choose a cursor library available to the data provider.
There are some differences in connection properties between SQLOLEDB and
MSDASQL. For information about connection properties for MSDASQL, see the
MSDN Library at Microsoft Web site.
If you are writing a connection string for use with SQLOLEDB:
Use the Initial Catalog property to specify the database.
Use the Data Source property to specify the server name.
Use the Integrated Security keyword, set to a value of SSPI, to specify
Windows Authentication (recommended),
or
use the User ID and Password connection properties to specify SQL Server
Authentication.
Security Note When possible, use Windows Authentication. If Windows
Authentication is not available, prompt users to enter their credentials at
run time. Avoid storing credentials in a file. If you must persist
credentials, you should encrypt them with the Win32 crypto API. For more
information, see "The Crypto API Function" in the MSDN Library at this
Microsoft Web site.
If you are writing a connection string for use with MSDASQL:
Use the Database keyword or Initial Catalog property to specify the
database.
Use the Server keyword or Data Source property to specify the server name.
Use the Trusted_Connection keyword, set to a value of yes, to specify
Windows Authentication (recommended),
or
Use the UID keyword or User ID property, and the Pwd keyword or Password
property to specify SQL Server Authentication.
Security Note When possible, use Windows Authentication. If Windows
Authentication is not available, prompt users to enter their credentials at
run time. Avoid storing credentials in a file. If you must persist
credentials, you should encrypt them with the Win32 crypto API. For more
information, see "The Crypto API Function" in the MSDN Library at this
Microsoft Web site.
For more information about a complete list of keywords available for use
with a SQLOLEDB connection string, see Connection Object.
Restrictions on Multiple Connections
SQLOLEDB does not allow multiple connections. Unlike MSDASQL, SQLOLEDB does
not attempt to reconnect when the connection is blocked.
Examples
A. Using SQLOLEDB to connect to an instance of SQL Server: setting
individual properties
The following Microsoft Visual Basic code fragments from the ADO
Introductory Visual Basic Sample show how to use SQLOLEDB to connect to an
instance of SQL Server.
' Initialize variables.
Dim cn As New ADODB.Connection
. . .
Dim ServerName As String, DatabaseName As String
' Put text box values into connection variables.
ServerName = txtServerName.Text
DatabaseName = txtDatabaseName.Text
' Specify the OLE DB provider.
cn.Provider = "sqloledb"
' Set SQLOLEDB connection properties.
cn.Properties("Data Source").Value = ServerName
cn.Properties("Initial Catalog").Value = DatabaseName
' Windows NT authentication.
cn.Properties("Integrated Security").Value = "SSPI"
' Open the database.
cn.Open
B. Using SQLOLEDB to connect to an instance of SQL Server: connection
string method
The following Visual Basic code fragment shows how to use SQLOLEDB to
connect to an instance or SQL Server:
' Initialize variables.
Dim cn As New ADODB.Connection
Dim provStr As String
' Specify the OLE DB provider.
cn.Provider = "sqloledb"
' Specify connection string on Open method.
ProvStr = "Server=MyServer;Database=northwind;Trusted_Connec tion=yes"
cn.Open provStr
C. Using MSDASQL to connect to an instance of SQL Server
To use MSDASQL to connect to an instance of SQL Server, use the following
types of connections.
The first type of connection is based on the ODBC API SQLConnect function.
This type of connection is useful in situations where you do not want to
code specific information about the data source. This may be the case if
the data source could change or if you do not know its particulars.
In the code fragment shown, the ConnectionTimeout method sets the
connection time-out value to 100 seconds. Next, the data source name, and
authentication type are passed as parameters to the Open method of the
Connection object, using an ODBC data source named MyDataSource that points
to the northwind database on an instance of SQL Server.
Dim cn As New ADODB.Connection
cn.ConnectionTimeout = 100
' DSN connection
' cn.Open "DSN=MyDataSource;Trusted_Connection=yes;"
cn.Close
The second type of connection is based on the ODBC API SQLDriverConnect
function. This type of connection is useful in situations where you want a
driver-specific connection string. To make a connection, use the Open
method of the Connection object and specify the driver, server name,
authentication type, and database. You can also specify any other valid
keywords to include in the connection string. For more information about
the keyword list, see SQLDriverConnect.
Dim cn As New ADODB.Connection
' Connection to SQL Server without using ODBC data source.
cn.Open "Driver={SQL
Server};Server=Server1;Database=northwind;Trusted_ Connection=yes"
cn.Close
Using the Connection Object
In addition to the Command object, an application can use the Connection
object to issue commands, stored procedures, and user-defined functions to
a database as if they were native methods on the Connection object. To
execute a query without using a Command object, an application can pass a
query string to the Execute method of a Connection object.
However, a Command object is required if you want to save and re-execute
the command text, or use query parameters.
To execute a command on the Connection object
Assign a name to the command using the Name property of the Command object.
Set the ActiveConnection property of the Command object to the connection.
Issue a statement where the command name is used as if it were a method on
the Connection object, followed by any parameters.
Create a Recordset object if any rows are returned.
Set the Recordset properties to customize the resulting Recordset.
Using the Connection Object to Execute Commands
This example shows how to use the Execute method of the Connection object
to execute commands.
Dim cn As New ADODB.Connection
. . .
Dim rs As New ADODB.Recordset
cmd1 = txtQuery.Text
Set rs = cn.Execute(cmd1)
After the Connection and Recordset objects are created, the variable cmd1
is assigned the value of a user-supplied query string (txtQuery.Text) from
a Microsoft Visual Basic form. The recordset is assigned the results of a
query, by calling the Execute method of the Connection object, with the
variable cmd1 used as the query string parameter.
Using the Recordset Object
The Recordset object provides methods for manipulating result sets. It
allows you to add, update, delete, and scroll through rows in the recordset.
A Recordset object can be created using the Execute method of the
Connection or Command object.
Each row in a recordset can also be retrieved and updated using the Fields
collection and the Field object. Updates on the Recordset object can be in
an immediate or batch mode. When a Recordset object is created, a cursor is
opened automatically.
The Recordset object allows you to specify the cursor type and location for
fetching the result set. With the CursorType property, you can specify
whether the cursor is read-only, forward-only, static, keyset-driven, or
dynamic. Cursor type determines if a Recordset object can be scrolled or
updated and affects the visibility of changed rows. By default, the cursor
type is read-only and forward-only.
An application can specify the location of the cursor with the
CursorLocation property. This property allows you to specify whether to use
a client or server cursor. The CursorLocation property setting is important
when you use disconnected recordsets.
The first part of the cmdExecute_Click method in the ADO Introductory
Visual Basic Sample shows an example of creating, opening, passing a
command string variable to, and positioning the cursor in a recordset.
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
. . .
cmd1 = txtQuery.Text
Set rs = New ADODB.Recordset
rs.Open cmd1, cn
rs.MoveFirst
. . .
' Code to loop through result set(s)
Thanks and regards,
Girish Sundaram
This posting is provided "AS IS" with no warranties, and confers no rights.
|||thank you for now
I will try
Probably I will turn back to you with some questions
"Girish Sundaram" wrote:
> Hi ,
> Please go through the following piece of information which will be useful
> in your case.
> ADO can use any OLE DB provider to establish a connection. The provider is
> specified through the Provider property of the Connection object.
> Microsoft? SQL Server? 2000 applications use SQLOLEDB to connect to an
> instance of SQL Server, although existing applications can also use MSDASQL
> to maintain backward compatibility.
> Using the Execute method of the Connection object is one way to execute an
> SQL statement against a SQL Server data source.
> The Connection object allows you to:
> Configure a connection.
>
> Establish and terminate sessions with data sources.
>
> Identify an OLE DB provider.
>
> Execute a query.
>
> Manage transactions on the open connection.
>
> Choose a cursor library available to the data provider.
> There are some differences in connection properties between SQLOLEDB and
> MSDASQL. For information about connection properties for MSDASQL, see the
> MSDN Library at Microsoft Web site.
> If you are writing a connection string for use with SQLOLEDB:
> Use the Initial Catalog property to specify the database.
>
> Use the Data Source property to specify the server name.
>
> Use the Integrated Security keyword, set to a value of SSPI, to specify
> Windows Authentication (recommended),
> or
> use the User ID and Password connection properties to specify SQL Server
> Authentication.
>
> Security Note When possible, use Windows Authentication. If Windows
> Authentication is not available, prompt users to enter their credentials at
> run time. Avoid storing credentials in a file. If you must persist
> credentials, you should encrypt them with the Win32? crypto API. For more
> information, see "The Crypto API Function" in the MSDN? Library at this
> Microsoft Web site.
> If you are writing a connection string for use with MSDASQL:
> Use the Database keyword or Initial Catalog property to specify the
> database.
>
> Use the Server keyword or Data Source property to specify the server name.
>
> Use the Trusted_Connection keyword, set to a value of yes, to specify
> Windows Authentication (recommended),
> or
> Use the UID keyword or User ID property, and the Pwd keyword or Password
> property to specify SQL Server Authentication.
>
> Security Note When possible, use Windows Authentication. If Windows
> Authentication is not available, prompt users to enter their credentials at
> run time. Avoid storing credentials in a file. If you must persist
> credentials, you should encrypt them with the Win32 crypto API. For more
> information, see "The Crypto API Function" in the MSDN Library at this
> Microsoft Web site.
> For more information about a complete list of keywords available for use
> with a SQLOLEDB connection string, see Connection Object.
> Restrictions on Multiple Connections
> SQLOLEDB does not allow multiple connections. Unlike MSDASQL, SQLOLEDB does
> not attempt to reconnect when the connection is blocked.
> Examples
> A. Using SQLOLEDB to connect to an instance of SQL Server: setting
> individual properties
> The following Microsoft Visual Basic? code fragments from the ADO
> Introductory Visual Basic Sample show how to use SQLOLEDB to connect to an
> instance of SQL Server.
> ' Initialize variables.
> Dim cn As New ADODB.Connection
> . . .
> Dim ServerName As String, DatabaseName As String
> ' Put text box values into connection variables.
> ServerName = txtServerName.Text
> DatabaseName = txtDatabaseName.Text
> ' Specify the OLE DB provider.
> cn.Provider = "sqloledb"
> ' Set SQLOLEDB connection properties.
> cn.Properties("Data Source").Value = ServerName
> cn.Properties("Initial Catalog").Value = DatabaseName
> ' Windows NT authentication.
> cn.Properties("Integrated Security").Value = "SSPI"
> ' Open the database.
> cn.Open
> B. Using SQLOLEDB to connect to an instance of SQL Server: connection
> string method
> The following Visual Basic code fragment shows how to use SQLOLEDB to
> connect to an instance or SQL Server:
> ' Initialize variables.
> Dim cn As New ADODB.Connection
> Dim provStr As String
> ' Specify the OLE DB provider.
> cn.Provider = "sqloledb"
> ' Specify connection string on Open method.
> ProvStr = "Server=MyServer;Database=northwind;Trusted_Connec tion=yes"
> cn.Open provStr
> C. Using MSDASQL to connect to an instance of SQL Server
> To use MSDASQL to connect to an instance of SQL Server, use the following
> types of connections.
> The first type of connection is based on the ODBC API SQLConnect function.
> This type of connection is useful in situations where you do not want to
> code specific information about the data source. This may be the case if
> the data source could change or if you do not know its particulars.
> In the code fragment shown, the ConnectionTimeout method sets the
> connection time-out value to 100 seconds. Next, the data source name, and
> authentication type are passed as parameters to the Open method of the
> Connection object, using an ODBC data source named MyDataSource that points
> to the northwind database on an instance of SQL Server.
> Dim cn As New ADODB.Connection
> cn.ConnectionTimeout = 100
> ' DSN connection
> ' cn.Open "DSN=MyDataSource;Trusted_Connection=yes;"
> cn.Close
> The second type of connection is based on the ODBC API SQLDriverConnect
> function. This type of connection is useful in situations where you want a
> driver-specific connection string. To make a connection, use the Open
> method of the Connection object and specify the driver, server name,
> authentication type, and database. You can also specify any other valid
> keywords to include in the connection string. For more information about
> the keyword list, see SQLDriverConnect.
> Dim cn As New ADODB.Connection
> ' Connection to SQL Server without using ODBC data source.
> cn.Open "Driver={SQL
> Server};Server=Server1;Database=northwind;Trusted_ Connection=yes"
> cn.Close
> Using the Connection Object
> In addition to the Command object, an application can use the Connection
> object to issue commands, stored procedures, and user-defined functions to
> a database as if they were native methods on the Connection object. To
> execute a query without using a Command object, an application can pass a
> query string to the Execute method of a Connection object.
> However, a Command object is required if you want to save and re-execute
> the command text, or use query parameters.
> To execute a command on the Connection object
> Assign a name to the command using the Name property of the Command object.
>
> Set the ActiveConnection property of the Command object to the connection.
>
> Issue a statement where the command name is used as if it were a method on
> the Connection object, followed by any parameters.
>
> Create a Recordset object if any rows are returned.
>
> Set the Recordset properties to customize the resulting Recordset.
> Using the Connection Object to Execute Commands
> This example shows how to use the Execute method of the Connection object
> to execute commands.
> Dim cn As New ADODB.Connection
> . . .
> Dim rs As New ADODB.Recordset
> cmd1 = txtQuery.Text
> Set rs = cn.Execute(cmd1)
> After the Connection and Recordset objects are created, the variable cmd1
> is assigned the value of a user-supplied query string (txtQuery.Text) from
> a Microsoft Visual Basic? form. The recordset is assigned the results of a
> query, by calling the Execute method of the Connection object, with the
> variable cmd1 used as the query string parameter.
> Using the Recordset Object
> The Recordset object provides methods for manipulating result sets. It
> allows you to add, update, delete, and scroll through rows in the recordset.
> A Recordset object can be created using the Execute method of the
> Connection or Command object.
> Each row in a recordset can also be retrieved and updated using the Fields
> collection and the Field object. Updates on the Recordset object can be in
> an immediate or batch mode. When a Recordset object is created, a cursor is
> opened automatically.
> The Recordset object allows you to specify the cursor type and location for
> fetching the result set. With the CursorType property, you can specify
> whether the cursor is read-only, forward-only, static, keyset-driven, or
> dynamic. Cursor type determines if a Recordset object can be scrolled or
> updated and affects the visibility of changed rows. By default, the cursor
> type is read-only and forward-only.
> An application can specify the location of the cursor with the
> CursorLocation property. This property allows you to specify whether to use
> a client or server cursor. The CursorLocation property setting is important
> when you use disconnected recordsets.
> The first part of the cmdExecute_Click method in the ADO Introductory
> Visual Basic Sample shows an example of creating, opening, passing a
> command string variable to, and positioning the cursor in a recordset.
> Dim cn As New ADODB.Connection
> Dim rs As ADODB.Recordset
> . . .
> cmd1 = txtQuery.Text
> Set rs = New ADODB.Recordset
> rs.Open cmd1, cn
> rs.MoveFirst
> . . .
> ' Code to loop through result set(s)
> Thanks and regards,
> Girish Sundaram
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
|||Ahmet, you could also look at www.asp.net. They have plenty of examples for
you on that site. You should be able to cut, paste, and modify.
"Ahmet Karaca" <AhmetKaraca@.discussions.microsoft.com> wrote in message
news:D99CE06D-E875-4084-919F-333C7840B6DC@.microsoft.com...[vbcol=seagreen]
> thank you for now
> I will try
> Probably I will turn back to you with some questions
> "Girish Sundaram" wrote:
useful[vbcol=seagreen]
is[vbcol=seagreen]
MSDASQL[vbcol=seagreen]
an[vbcol=seagreen]
the[vbcol=seagreen]
at[vbcol=seagreen]
more[vbcol=seagreen]
name.[vbcol=seagreen]
at[vbcol=seagreen]
does[vbcol=seagreen]
an[vbcol=seagreen]
following[vbcol=seagreen]
function.[vbcol=seagreen]
and[vbcol=seagreen]
points[vbcol=seagreen]
a[vbcol=seagreen]
to[vbcol=seagreen]
a[vbcol=seagreen]
object.[vbcol=seagreen]
connection.[vbcol=seagreen]
on[vbcol=seagreen]
object[vbcol=seagreen]
cmd1[vbcol=seagreen]
from[vbcol=seagreen]
a[vbcol=seagreen]
recordset.[vbcol=seagreen]
Fields[vbcol=seagreen]
in[vbcol=seagreen]
is[vbcol=seagreen]
for[vbcol=seagreen]
cursor[vbcol=seagreen]
use[vbcol=seagreen]
important[vbcol=seagreen]
rights.[vbcol=seagreen]
Online query to my database
queries to my database over the net by a GUI developed in Visual Studio .NET
.
Could someone explain the procedure I must follow to accomplish such an aim.
I mean that database is in the desktop computer in my house and I want to
make query from my friend's desktop computer which is somewhere else. Hence,
I need something that should be performed over the net.
Thanls in advanceHi ,
Please go through the following piece of information which will be useful
in your case.
ADO can use any OLE DB provider to establish a connection. The provider is
specified through the Provider property of the Connection object.
Microsoft SQL Server 2000 applications use SQLOLEDB to connect to an
instance of SQL Server, although existing applications can also use MSDASQL
to maintain backward compatibility.
Using the Execute method of the Connection object is one way to execute an
SQL statement against a SQL Server data source.
The Connection object allows you to:
Configure a connection.
Establish and terminate sessions with data sources.
Identify an OLE DB provider.
Execute a query.
Manage transactions on the open connection.
Choose a cursor library available to the data provider.
There are some differences in connection properties between SQLOLEDB and
MSDASQL. For information about connection properties for MSDASQL, see the
MSDN Library at Microsoft Web site.
If you are writing a connection string for use with SQLOLEDB:
Use the Initial Catalog property to specify the database.
Use the Data Source property to specify the server name.
Use the Integrated Security keyword, set to a value of SSPI, to specify
Windows Authentication (recommended),
or
use the User ID and Password connection properties to specify SQL Server
Authentication.
Security Note When possible, use Windows Authentication. If Windows
Authentication is not available, prompt users to enter their credentials at
run time. Avoid storing credentials in a file. If you must persist
credentials, you should encrypt them with the Win32 crypto API. For more
information, see "The Crypto API Function" in the MSDN Library at this
Microsoft Web site.
If you are writing a connection string for use with MSDASQL:
Use the Database keyword or Initial Catalog property to specify the
database.
Use the Server keyword or Data Source property to specify the server name.
Use the Trusted_Connection keyword, set to a value of yes, to specify
Windows Authentication (recommended),
or
Use the UID keyword or User ID property, and the Pwd keyword or Password
property to specify SQL Server Authentication.
Security Note When possible, use Windows Authentication. If Windows
Authentication is not available, prompt users to enter their credentials at
run time. Avoid storing credentials in a file. If you must persist
credentials, you should encrypt them with the Win32 crypto API. For more
information, see "The Crypto API Function" in the MSDN Library at this
Microsoft Web site.
For more information about a complete list of keywords available for use
with a SQLOLEDB connection string, see Connection Object.
Restrictions on Multiple Connections
SQLOLEDB does not allow multiple connections. Unlike MSDASQL, SQLOLEDB does
not attempt to reconnect when the connection is blocked.
Examples
A. Using SQLOLEDB to connect to an instance of SQL Server: setting
individual properties
The following Microsoft Visual Basic code fragments from the ADO
Introductory Visual Basic Sample show how to use SQLOLEDB to connect to an
instance of SQL Server.
' Initialize variables.
Dim cn As New ADODB.Connection
. . .
Dim ServerName As String, DatabaseName As String
' Put text box values into connection variables.
ServerName = txtServerName.Text
DatabaseName = txtDatabaseName.Text
' Specify the OLE DB provider.
cn.Provider = "sqloledb"
' Set SQLOLEDB connection properties.
cn.Properties("Data Source").Value = ServerName
cn.Properties("Initial Catalog").Value = DatabaseName
' Windows NT authentication.
cn.Properties("Integrated Security").Value = "SSPI"
' Open the database.
cn.Open
B. Using SQLOLEDB to connect to an instance of SQL Server: connection
string method
The following Visual Basic code fragment shows how to use SQLOLEDB to
connect to an instance or SQL Server:
' Initialize variables.
Dim cn As New ADODB.Connection
Dim provStr As String
' Specify the OLE DB provider.
cn.Provider = "sqloledb"
' Specify connection string on Open method.
ProvStr = " Server=MyServer;Database=northwind;Trust
ed_Connection=yes"
cn.Open provStr
C. Using MSDASQL to connect to an instance of SQL Server
To use MSDASQL to connect to an instance of SQL Server, use the following
types of connections.
The first type of connection is based on the ODBC API SQLConnect function.
This type of connection is useful in situations where you do not want to
code specific information about the data source. This may be the case if
the data source could change or if you do not know its particulars.
In the code fragment shown, the ConnectionTimeout method sets the
connection time-out value to 100 seconds. Next, the data source name, and
authentication type are passed as parameters to the Open method of the
Connection object, using an ODBC data source named MyDataSource that points
to the northwind database on an instance of SQL Server.
Dim cn As New ADODB.Connection
cn.ConnectionTimeout = 100
' DSN connection
' cn.Open " DSN=MyDataSource;Trusted_Connection=yes;
"
cn.Close
The second type of connection is based on the ODBC API SQLDriverConnect
function. This type of connection is useful in situations where you want a
driver-specific connection string. To make a connection, use the Open
method of the Connection object and specify the driver, server name,
authentication type, and database. You can also specify any other valid
keywords to include in the connection string. For more information about
the keyword list, see SQLDriverConnect.
Dim cn As New ADODB.Connection
' Connection to SQL Server without using ODBC data source.
cn.Open "Driver={SQL
Server};Server=Server1;Database=northwin
d;Trusted_Connection=yes"
cn.Close
Using the Connection Object
In addition to the Command object, an application can use the Connection
object to issue commands, stored procedures, and user-defined functions to
a database as if they were native methods on the Connection object. To
execute a query without using a Command object, an application can pass a
query string to the Execute method of a Connection object.
However, a Command object is required if you want to save and re-execute
the command text, or use query parameters.
To execute a command on the Connection object
Assign a name to the command using the Name property of the Command object.
Set the ActiveConnection property of the Command object to the connection.
Issue a statement where the command name is used as if it were a method on
the Connection object, followed by any parameters.
Create a Recordset object if any rows are returned.
Set the Recordset properties to customize the resulting Recordset.
Using the Connection Object to Execute Commands
This example shows how to use the Execute method of the Connection object
to execute commands.
Dim cn As New ADODB.Connection
. . .
Dim rs As New ADODB.Recordset
cmd1 = txtQuery.Text
Set rs = cn.Execute(cmd1)
After the Connection and Recordset objects are created, the variable cmd1
is assigned the value of a user-supplied query string (txtQuery.Text) from
a Microsoft Visual Basic form. The recordset is assigned the results of a
query, by calling the Execute method of the Connection object, with the
variable cmd1 used as the query string parameter.
Using the Recordset Object
The Recordset object provides methods for manipulating result sets. It
allows you to add, update, delete, and scroll through rows in the recordset.
A Recordset object can be created using the Execute method of the
Connection or Command object.
Each row in a recordset can also be retrieved and updated using the Fields
collection and the Field object. Updates on the Recordset object can be in
an immediate or batch mode. When a Recordset object is created, a cursor is
opened automatically.
The Recordset object allows you to specify the cursor type and location for
fetching the result set. With the CursorType property, you can specify
whether the cursor is read-only, forward-only, static, keyset-driven, or
dynamic. Cursor type determines if a Recordset object can be scrolled or
updated and affects the visibility of changed rows. By default, the cursor
type is read-only and forward-only.
An application can specify the location of the cursor with the
CursorLocation property. This property allows you to specify whether to use
a client or server cursor. The CursorLocation property setting is important
when you use disconnected recordsets.
The first part of the cmdExecute_Click method in the ADO Introductory
Visual Basic Sample shows an example of creating, opening, passing a
command string variable to, and positioning the cursor in a recordset.
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
. . .
cmd1 = txtQuery.Text
Set rs = New ADODB.Recordset
rs.Open cmd1, cn
rs.MoveFirst
. . .
' Code to loop through result set(s)
Thanks and regards,
Girish Sundaram
This posting is provided "AS IS" with no warranties, and confers no rights.|||thank you for now
I will try
Probably I will turn back to you with some questions
"Girish Sundaram" wrote:
> Hi ,
> Please go through the following piece of information which will be useful
> in your case.
> ADO can use any OLE DB provider to establish a connection. The provider is
> specified through the Provider property of the Connection object.
> Microsoft? SQL Server? 2000 applications use SQLOLEDB to connect to an
> instance of SQL Server, although existing applications can also use MSDASQ
L
> to maintain backward compatibility.
> Using the Execute method of the Connection object is one way to execute an
> SQL statement against a SQL Server data source.
> The Connection object allows you to:
> Configure a connection.
>
> Establish and terminate sessions with data sources.
>
> Identify an OLE DB provider.
>
> Execute a query.
>
> Manage transactions on the open connection.
>
> Choose a cursor library available to the data provider.
> There are some differences in connection properties between SQLOLEDB and
> MSDASQL. For information about connection properties for MSDASQL, see the
> MSDN Library at Microsoft Web site.
> If you are writing a connection string for use with SQLOLEDB:
> Use the Initial Catalog property to specify the database.
>
> Use the Data Source property to specify the server name.
>
> Use the Integrated Security keyword, set to a value of SSPI, to specify
> Windows Authentication (recommended),
> or
> use the User ID and Password connection properties to specify SQL Server
> Authentication.
>
> Security Note When possible, use Windows Authentication. If Windows
> Authentication is not available, prompt users to enter their credentials a
t
> run time. Avoid storing credentials in a file. If you must persist
> credentials, you should encrypt them with the Win32? crypto API. For more
> information, see "The Crypto API Function" in the MSDN? Library at this
> Microsoft Web site.
> If you are writing a connection string for use with MSDASQL:
> Use the Database keyword or Initial Catalog property to specify the
> database.
>
> Use the Server keyword or Data Source property to specify the server name.
>
> Use the Trusted_Connection keyword, set to a value of yes, to specify
> Windows Authentication (recommended),
> or
> Use the UID keyword or User ID property, and the Pwd keyword or Password
> property to specify SQL Server Authentication.
>
> Security Note When possible, use Windows Authentication. If Windows
> Authentication is not available, prompt users to enter their credentials a
t
> run time. Avoid storing credentials in a file. If you must persist
> credentials, you should encrypt them with the Win32 crypto API. For more
> information, see "The Crypto API Function" in the MSDN Library at this
> Microsoft Web site.
> For more information about a complete list of keywords available for use
> with a SQLOLEDB connection string, see Connection Object.
> Restrictions on Multiple Connections
> SQLOLEDB does not allow multiple connections. Unlike MSDASQL, SQLOLEDB doe
s
> not attempt to reconnect when the connection is blocked.
> Examples
> A. Using SQLOLEDB to connect to an instance of SQL Server: setting
> individual properties
> The following Microsoft Visual Basic? code fragments from the ADO
> Introductory Visual Basic Sample show how to use SQLOLEDB to connect to an
> instance of SQL Server.
> ' Initialize variables.
> Dim cn As New ADODB.Connection
> . . .
> Dim ServerName As String, DatabaseName As String
> ' Put text box values into connection variables.
> ServerName = txtServerName.Text
> DatabaseName = txtDatabaseName.Text
> ' Specify the OLE DB provider.
> cn.Provider = "sqloledb"
> ' Set SQLOLEDB connection properties.
> cn.Properties("Data Source").Value = ServerName
> cn.Properties("Initial Catalog").Value = DatabaseName
> ' Windows NT authentication.
> cn.Properties("Integrated Security").Value = "SSPI"
> ' Open the database.
> cn.Open
> B. Using SQLOLEDB to connect to an instance of SQL Server: connection
> string method
> The following Visual Basic code fragment shows how to use SQLOLEDB to
> connect to an instance or SQL Server:
> ' Initialize variables.
> Dim cn As New ADODB.Connection
> Dim provStr As String
> ' Specify the OLE DB provider.
> cn.Provider = "sqloledb"
> ' Specify connection string on Open method.
> ProvStr = " Server=MyServer;Database=northwind;Trust
ed_Connection=yes"
> cn.Open provStr
> C. Using MSDASQL to connect to an instance of SQL Server
> To use MSDASQL to connect to an instance of SQL Server, use the following
> types of connections.
> The first type of connection is based on the ODBC API SQLConnect function.
> This type of connection is useful in situations where you do not want to
> code specific information about the data source. This may be the case if
> the data source could change or if you do not know its particulars.
> In the code fragment shown, the ConnectionTimeout method sets the
> connection time-out value to 100 seconds. Next, the data source name, and
> authentication type are passed as parameters to the Open method of the
> Connection object, using an ODBC data source named MyDataSource that point
s
> to the northwind database on an instance of SQL Server.
> Dim cn As New ADODB.Connection
> cn.ConnectionTimeout = 100
> ' DSN connection
> ' cn.Open " DSN=MyDataSource;Trusted_Connection=yes;
"
> cn.Close
> The second type of connection is based on the ODBC API SQLDriverConnect
> function. This type of connection is useful in situations where you want a
> driver-specific connection string. To make a connection, use the Open
> method of the Connection object and specify the driver, server name,
> authentication type, and database. You can also specify any other valid
> keywords to include in the connection string. For more information about
> the keyword list, see SQLDriverConnect.
> Dim cn As New ADODB.Connection
> ' Connection to SQL Server without using ODBC data source.
> cn.Open "Driver={SQL
> Server};Server=Server1;Database=northwin
d;Trusted_Connection=yes"
> cn.Close
> Using the Connection Object
> In addition to the Command object, an application can use the Connection
> object to issue commands, stored procedures, and user-defined functions to
> a database as if they were native methods on the Connection object. To
> execute a query without using a Command object, an application can pass a
> query string to the Execute method of a Connection object.
> However, a Command object is required if you want to save and re-execute
> the command text, or use query parameters.
> To execute a command on the Connection object
> Assign a name to the command using the Name property of the Command object
.
>
> Set the ActiveConnection property of the Command object to the connection.
>
> Issue a statement where the command name is used as if it were a method on
> the Connection object, followed by any parameters.
>
> Create a Recordset object if any rows are returned.
>
> Set the Recordset properties to customize the resulting Recordset.
> Using the Connection Object to Execute Commands
> This example shows how to use the Execute method of the Connection object
> to execute commands.
> Dim cn As New ADODB.Connection
> . . .
> Dim rs As New ADODB.Recordset
> cmd1 = txtQuery.Text
> Set rs = cn.Execute(cmd1)
> After the Connection and Recordset objects are created, the variable cmd1
> is assigned the value of a user-supplied query string (txtQuery.Text) from
> a Microsoft Visual Basic? form. The recordset is assigned the results of
a
> query, by calling the Execute method of the Connection object, with the
> variable cmd1 used as the query string parameter.
> Using the Recordset Object
> The Recordset object provides methods for manipulating result sets. It
> allows you to add, update, delete, and scroll through rows in the recordse
t.
> A Recordset object can be created using the Execute method of the
> Connection or Command object.
> Each row in a recordset can also be retrieved and updated using the Fields
> collection and the Field object. Updates on the Recordset object can be in
> an immediate or batch mode. When a Recordset object is created, a cursor i
s
> opened automatically.
> The Recordset object allows you to specify the cursor type and location fo
r
> fetching the result set. With the CursorType property, you can specify
> whether the cursor is read-only, forward-only, static, keyset-driven, or
> dynamic. Cursor type determines if a Recordset object can be scrolled or
> updated and affects the visibility of changed rows. By default, the cursor
> type is read-only and forward-only.
> An application can specify the location of the cursor with the
> CursorLocation property. This property allows you to specify whether to us
e
> a client or server cursor. The CursorLocation property setting is importan
t
> when you use disconnected recordsets.
> The first part of the cmdExecute_Click method in the ADO Introductory
> Visual Basic Sample shows an example of creating, opening, passing a
> command string variable to, and positioning the cursor in a recordset.
> Dim cn As New ADODB.Connection
> Dim rs As ADODB.Recordset
> . . .
> cmd1 = txtQuery.Text
> Set rs = New ADODB.Recordset
> rs.Open cmd1, cn
> rs.MoveFirst
> . . .
> ' Code to loop through result set(s)
> Thanks and regards,
> Girish Sundaram
>
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>|||Ahmet, you could also look at www.asp.net. They have plenty of examples for
you on that site. You should be able to cut, paste, and modify.
"Ahmet Karaca" <AhmetKaraca@.discussions.microsoft.com> wrote in message
news:D99CE06D-E875-4084-919F-333C7840B6DC@.microsoft.com...[vbcol=seagreen]
> thank you for now
> I will try
> Probably I will turn back to you with some questions
> "Girish Sundaram" wrote:
>
useful[vbcol=seagreen]
is[vbcol=seagreen]
MSDASQL[vbcol=seagreen]
an[vbcol=seagreen]
the[vbcol=seagreen]
at[vbcol=seagreen]
more[vbcol=seagreen]
name.[vbcol=seagreen]
at[vbcol=seagreen]
does[vbcol=seagreen]
an[vbcol=seagreen]
following[vbcol=seagreen]
function.[vbcol=seagreen]
and[vbcol=seagreen]
points[vbcol=seagreen]
a[vbcol=seagreen]
to[vbcol=seagreen]
a[vbcol=seagreen]
object.[vbcol=seagreen]
connection.[vbcol=seagreen]
on[vbcol=seagreen]
object[vbcol=seagreen]
cmd1[vbcol=seagreen]
from[vbcol=seagreen]
a[vbcol=seagreen]
recordset.[vbcol=seagreen]
Fields[vbcol=seagreen]
in[vbcol=seagreen]
is[vbcol=seagreen]
for[vbcol=seagreen]
cursor[vbcol=seagreen]
use[vbcol=seagreen]
important[vbcol=seagreen]
rights.[vbcol=seagreen]