Developer forum

Forum » Development » SQL server access question

SQL server access question

Dmitrij Jazel
Reply

hello guys,

Just wanted to know if there is any difference between 2 ways of accessing database:

1) when DW is accessing it's database by using GlobalSettings

2) if I would make a custom user control with my new database connection object etc...

 

Because we have an issue here. there is a DW website hosted remotely, I made a small user control that gathers some data and some logic, nothing special... user control is called inside a design template.

as a result:

DW site is working Perfectly :) it connects to the same database all is great.

But my user control complains that "the network path was not found" [Win32Exception (0x80004005): The network path was not found]

So I just wanted to know if there is any difference how DW establishes and manages it's connections and how I do it.

I include a text file with C# code and example of connection string

Database server and server instance, dbuser and dbpass is the same I am using in GlobalSettings

 

As a last option, maybe there is a way to access DW SQL connection through API and perform SQL operations through it?

 

Dmitrij

 

 


Replies

 
Dmitrij Jazel
Reply

Hi Morten,

User control is calling the same database as its' DW application is calling,

This database is another physical machine withing same local network. There are no restrictions within local network.

As a result DW application is running - this surely means that database is there and it is accessible - otherwise application would not run.

But I am using exactly the same credentials, there should be nothing else in it's way...

 

 
Morten Bengtson
Reply

If your connection string contains a backslash (\) then make sure it is not treated as an escape sequence.

Did you try hard coding the connection string and verify that it works?

Did you try this using Dynamicweb.Database.CreateConnection() ?

 
Dmitrij Jazel
Reply

Hello Morten,

First when I was using "hardcoded server instance name" I had to use "\\" as you brought here, but if I am adding it as a entry in web.config it is enough to have "\".

I tried hardcoding this connectionstring and I run into the same issue.

 

regarding Dynamicweb.Database.CreateConnection() I thought about it, that is one of the reason why I am here, maybe I could have an example on this one?

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

The error number you're getting (0x80004005) tells me this is a security issue. Are you sure you're targeting the correct server, database and user account? Are you sure it's identical to what is in DW's GlobalSettings and are you sure you're using / reading

the correct web.config?

 

Imar

 
Dmitrij Jazel
Reply

Hej Imar,

Thanks allot for info, well username and password are correct, and I tried both "sa" and "sql login" I made for dynamicweb user. Normally I just use that dynamicwebs user, same is GlobalSettings, and it works just great.

I am absolutely sure that I am targeting correct server with correct instance, and it is identical to one DW is using. And Web config, well there is only one and only web.config in the root folder.

 

 

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

If the Dynamicweb database connections are working properly, then you could consider using the Dynamicweb.Database class to communicate with the database. That is the API that Dynamicweb uses internally to facilitate database queries.

 

The class gives you access to Connections, DataReaders, DataTables and DataSets, among other handy database tools. Read more here: http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.Database.html

 

- Jeppe

 
Dmitrij Jazel
Reply

Hej Jeppe,

I am looking at it right now, and as I can see that is exactly what Morten B sugged "Dynamicweb.Database.CreateConnection()" right?
Quick question here than, things I found strange, I still had to provide connection string to a dwconnection, But diesn't ir get it automatically from GlobalSettings?

And how about executing the reader? Normally I call SqlDataReader reader = command.ExecuteReader();

Do I have to do something like this here aswell or should I go straight to dwconnection.Open(); and while (dwreader.Read()) ?

 

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

You don't have to create the connection manually, it's all taken care of by Dynamicweb. All you need to do is to call CreateDataReader and dispose the object when you're done.

 

You can see sample code when clicking on the method in the API documentation, or go here: http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.Database~CreateDataReader%28String%29.html

Votes for this answer: 1
 
Dmitrij Jazel
Reply

Hej Jeppe,

Can't express my gratitude :-) worked like a charm!

 

 

 

 

You must be logged in to post in the forum