Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Sunday, March 25, 2012

Connetion VS2003 C# Web Service to Sql Server 2005 Express

Hi,

I'm reaching the end of my tether here. I'm writing a Web Service application for my MCAD course in VS2003 which will connect to a SQL Server 2005 Express instance to access data. I can connect to the instance through the management suite, and through Visual Studio 2003. For some reason, when I try and manually connect through the web service, I get a page cannot be displayed error. When debugging, it falls over at the connection code. Here's what I have:

<appSettings>

<add key="ConnectionString" value="Integrated Security=SSPI;Initial Catalog=OfficeSupplies;Data Source=SGODRICH\SQLEXPRESS;"/>

</appSettings>

in web.config, and in my application:

// Create a connection to SQL Server Express

connection = new SqlConnection(ConnectionInfo);

// Upload Customer data to DataTable

dataadapter1 = new SqlDataAdapter("select * from Customers", connection);

dataadapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey;

Customer_Data = new DataTable("Customers");

dataadapter1.Fill(Customer_Data);

The line in red is where the application falls over and I get a page cannot be displayed error. Any ideas why my application can't connect yet I can through both the manager and the IDE? I have enabled TCP, named pipes and shared memory. I have TCP dynamic port of 1053, I can connect using SQLCMD -S.\SQLEXPRESS from the command prompt (I get a 1> when I do this). I also have both services up and running. Anyone have any idea?

If the error happens in the red line, then your connection string is wrong. The error occurs in the constructor of the sqlconnection class not during connection which would be the .Open() method.

HTH, jens Suessmeyer.

http://www.sqlserver2005.de|||Ooops. My apologies. I guess working so close to a problem blinds you to its issues. Its working fine now. Well, for now...

Tuesday, March 20, 2012

Connections to the DB

Hi,
Is there a way of finding if there are connections to a SQL Database with T-SQL?

I am writing a routine that will crate a copy of the main Database files and to do this i needed to make sure that there are no other uses connected before i Unattach the DB and copy the files.

It would also be useful if i can tell the end user which user are connected.select * from master.sys.syslogins
_

? www.carlop.com × carlop-dev.blogspot.com

sqlsql

Monday, March 19, 2012

connections

im writing a service that will be on a app server
this is one of many service's to process Recordsets from Sql Server...
1 service may have 20 Processes to Complete
example
main class PreProcess()
method CleanNames();
method updateNames();
methodr ValidateContracts();
Various things must be completed
Suedo Example below
My question is
in the main class make my connection and keep it for all sub members
or connect in each member
A. This Way opens connection...closes connect

method cleanNames()
1 get connection
2 get recordset
3. Close Connection
4 process Recordset
5. Open Connection
4 Commit Changes
6. Close Connection()
finished cleanames()
or
method cleanNames()
1 get connection
2 get recordset
3 process Recordset
4 Commit Changes
5. Close Connection()
finished cleanames()
or
this final way is in the parent Class or Calling Function
sends in the connections holds it open till the service is
completed of all jobs its Suppose to do
then releases the connection

method cleanNames(oconn) connection as parameter
1 get recordset
2 process Recordset
3 Commit Changes
finished cleanames()

Thanks
DavePDaveP (dvs_bis@.sbcglobal.net) writes:

Quote:

Originally Posted by

im writing a service that will be on a app server
this is one of many service's to process Recordsets from Sql Server...
1 service may have 20 Processes to Complete
example
main class PreProcess()
method CleanNames();
method updateNames();
methodr ValidateContracts();
Various things must be completed
Suedo Example below
My question is
in the main class make my connection and keep it for all sub members
or connect in each member


I'm not really sure I understand, but if the members are intended to
be separate threads, you should definitely have one connection per
member.

If they are just different tasks that a single-threaded service will
perform, it's more of a toss-up, but I think the idiom today is to stick
with local connections. Keep in mind that ADO .Net maintains a connection
pool where it lingers to disconnected connections and then reuse them
if there is a request for a connect with the same properties within
some timefram (60 seconds, I believe).

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx