[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Re: Problem Connecting to local DB

Dino Chiesa [MSFT]

7/18/2003 11:19:00 PM

This is the wrong newsgroup, since it is a data access thing, and not a
webservices thing.

But,
1st, the SQL provider is for Ms SQL Server, not for MS Access databases.
check the doc:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClas...
It will not resolve the "database name" you specify to be a "DSN". If you
want to open a foo.mdb, then the first approach you took is the right one.
I think there is also an option to use the Odbc client with a DSN. See
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOdbcOdbcConnectionClas...

2nd, If in case 2 you in fact are trying to connect to MS SQL, you want to
specify in your connection string, the servername (probably not (local) but
possibly "localhost" (no quotes)), and the name of the database on the
server. Eg, Northwind, pubs, master, etc. This is not a *.mdb file, but
it is the name of a database on a SQL Server.

3rd, your connection string includes userid/pw as well as integrated
security. I believe it is an either-or proposition.


"George Stathis" <george@yahoo.com> wrote in message
news:%23TOp0uUTDHA.2188@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I'm setting up a simple test Web Service. I am testing two different
methods
> of connecting to a local test database. One with a OleDbConnection object
> and one with an SqlConnection object. The OleDbConnection methods works
> fine:
>
> [WebMethod]
> public DataSet GetMyData() {
> string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
> Services=-4; Data Source=C:\\Inetpub\\wwwroot\\MyApp\\MyDB.mdb";
> OleDbConnection dbConnection = new OleDbConnection(connectionString);
>
> string queryString = "SELECT * FROM tblNames";
>
> OleDbDataAdapter dataAdapter = new
> OleDbDataAdapter(queryString,dbConnection);
>
> DataSet dataSet = new DataSet();
>
> try {
> dataAdapter.Fill(dataSet,"NAMES");
> }
> catch (Exception e) {
> throw new ApplicationException(e.Message,e.InnerException);
> }
>
> return dataSet;
> }
>
> I get my XML WSDL and see my data fine.
>
> The SqlConnection method does not connect:
>
> [WebMethod]
> public DataSet GetMyData2() {
>
> //create the connection string and sql to be executed
> string strConnTxt = "SERVER=(local);uid=;pwd=;Database=MyDB;Integrated
> Security=True;";
>
> //create and open the connection object
> SqlConnection objConn = new SqlConnection(strConnTxt);
> try{
> objConn.Open();
> }
> catch (Exception e) {
> throw new ApplicationException(e.Message,e.InnerException);
> }
>
> //Create the command object
> string strSql = "select * from tblNames";
> SqlCommand objCmd = new SqlCommand(strSql, objConn);
> objCmd.CommandType = CommandType.Text;
>
> SqlDataAdapter da=new SqlDataAdapter(objCmd);
> DataSet dataSet = new DataSet();
> try {
> da.Fill(dataSet);
> }
> catch (Exception e) {
> throw new ApplicationException(e.Message,e.InnerException);
> }
>
> objConn.Close();
> return dataSet;
> }
>
> I get a "The page cannot be displayed" error. The only difference that I
can
> think of is that in the first method, the database is referred to by path.
> In the second case, it's referred to by DSN. I have added it of course to
> the System Data Sources under Administrative Tools>Data Sources (ODBC).
>
> I can't figure out why it's not being seen when invoked in this manner.
Any
> ideas?
>
> Thank you in advance for your time.
>
> GS
>
>


2 Answers

George

7/19/2003 4:26:00 AM

0

Thank you. This definitely helps.


"Dino Chiesa [MSFT]" <dinoch@microsoft.com> wrote in message
news:eBv7IMYTDHA.1552@TK2MSFTNGP10.phx.gbl...
> This is the wrong newsgroup, since it is a data access thing, and not a
> webservices thing.
>
> But,
> 1st, the SQL provider is for Ms SQL Server, not for MS Access databases.
> check the doc:
>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClas...
> It will not resolve the "database name" you specify to be a "DSN". If
you
> want to open a foo.mdb, then the first approach you took is the right one.
> I think there is also an option to use the Odbc client with a DSN. See
>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOdbcOdbcConnectionClas...
>
> 2nd, If in case 2 you in fact are trying to connect to MS SQL, you want to
> specify in your connection string, the servername (probably not (local)
but
> possibly "localhost" (no quotes)), and the name of the database on the
> server. Eg, Northwind, pubs, master, etc. This is not a *.mdb file,
but
> it is the name of a database on a SQL Server.
>
> 3rd, your connection string includes userid/pw as well as integrated
> security. I believe it is an either-or proposition.
>
>
> "George Stathis" <george@yahoo.com> wrote in message
> news:%23TOp0uUTDHA.2188@TK2MSFTNGP10.phx.gbl...
> > Hello,
> >
> > I'm setting up a simple test Web Service. I am testing two different
> methods
> > of connecting to a local test database. One with a OleDbConnection
object
> > and one with an SqlConnection object. The OleDbConnection methods works
> > fine:
> >
> > [WebMethod]
> > public DataSet GetMyData() {
> > string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
> > Services=-4; Data Source=C:\\Inetpub\\wwwroot\\MyApp\\MyDB.mdb";
> > OleDbConnection dbConnection = new
OleDbConnection(connectionString);
> >
> > string queryString = "SELECT * FROM tblNames";
> >
> > OleDbDataAdapter dataAdapter = new
> > OleDbDataAdapter(queryString,dbConnection);
> >
> > DataSet dataSet = new DataSet();
> >
> > try {
> > dataAdapter.Fill(dataSet,"NAMES");
> > }
> > catch (Exception e) {
> > throw new ApplicationException(e.Message,e.InnerException);
> > }
> >
> > return dataSet;
> > }
> >
> > I get my XML WSDL and see my data fine.
> >
> > The SqlConnection method does not connect:
> >
> > [WebMethod]
> > public DataSet GetMyData2() {
> >
> > //create the connection string and sql to be executed
> > string strConnTxt =
"SERVER=(local);uid=;pwd=;Database=MyDB;Integrated
> > Security=True;";
> >
> > //create and open the connection object
> > SqlConnection objConn = new SqlConnection(strConnTxt);
> > try{
> > objConn.Open();
> > }
> > catch (Exception e) {
> > throw new ApplicationException(e.Message,e.InnerException);
> > }
> >
> > //Create the command object
> > string strSql = "select * from tblNames";
> > SqlCommand objCmd = new SqlCommand(strSql, objConn);
> > objCmd.CommandType = CommandType.Text;
> >
> > SqlDataAdapter da=new SqlDataAdapter(objCmd);
> > DataSet dataSet = new DataSet();
> > try {
> > da.Fill(dataSet);
> > }
> > catch (Exception e) {
> > throw new ApplicationException(e.Message,e.InnerException);
> > }
> >
> > objConn.Close();
> > return dataSet;
> > }
> >
> > I get a "The page cannot be displayed" error. The only difference that I
> can
> > think of is that in the first method, the database is referred to by
path.
> > In the second case, it's referred to by DSN. I have added it of course
to
> > the System Data Sources under Administrative Tools>Data Sources (ODBC).
> >
> > I can't figure out why it's not being seen when invoked in this manner.
> Any
> > ideas?
> >
> > Thank you in advance for your time.
> >
> > GS
> >
> >
>
>


Dänk 42Ö

7/25/2011 6:05:00 PM

0

On 2011-07-24 23:31, 6139 Dead, 1282 since 1/20/09 wrote:
> On Sun, 24 Jul 2011 20:37:26 -0700, mange@merde.com wrote:
>> The "greedy" bankers (yet he fails to mention the "greedy" 47% of
>> "Americans") who pay NOTHING in federal income taxes!!!
>
> Well, then, it's very simple. All those poor billionaires have to do is
> give up all their worldly possession, and get jobs at hamburger joints.
> Then they, too, will be in the "lucky" 47%!

If you hate billionaires so much, perhaps you should boycott them by refusing to purchase the
products their companies produce.

Here is a list of the 400 richest Americans:

http://www.forbes.com/wealth/forbe...

Examine the list and determine which of their companies make products that you think you and
your fellow hamburger flippers can replicate. Go ahead and design the next generation of
multi-core microprocessors or new iThing, then decide how much profit to keep for yourself and
how much to share with your secretary and janitor.

The combined wealth of the Forbes 400 is $1.37 trillion. Even if you sent them all to the
guillotine and confiscated their estates, you would still be $230 billion short of the amount
needed to cover this year's $1.6 trillion budget deficit. And $1.37 is just their personal
wealth, derived from the many more trillions of dollars of wealth their companies generate.
Behead the American billionaire, and his company will fall to to the Chinese billionaire's
company, and the U.S. government loses out on those tax revenues and our economic and national
security is weakened.

= = = = = = = = = = = = = = = = = =
Quack Quack for Obama Crack!
http://obamacrack.gofre...