Showing posts with label sqlconnection. Show all posts
Showing posts with label sqlconnection. Show all posts

Tuesday, March 20, 2012

ConnectionString

Hi
I'm using Sql Server (SQLOLEDB.1) and I want to connect it by Sqlconnection.
those are the details:
user Id: sa
Password: *****
database: ServiceManagement
server name: KLXPE002\KULMOS
What should be the Connection String?
Thats what i did:

"Persist Security Info=True;Integrated Security=SSPI;server=SQLOLEDB.1;database=ServiceManagement;Data Source=KLXPE002\KULMOS;User ID=sa;password=****"
It doesn't work.
thnx
Itai

Hi,
Your connection string should look like
"Data Source=KLXPE002\KULMOS;Initial Catalog=ServiceManagement;User Id=sa;Password=asdasd;"

Regards,
Venkatarajan A|||You can visit this site:www.connectionStrings.com|||thank you Venkatarajan its working

Wednesday, March 7, 2012

Connection Timeout

In one of my applications I want to set a connection timeout to 1 second when connecting to the SQL Server. .NET's SqlConnection already has connectiontimeout property as readonly and set to 15 seconds. So I cant use it. And if I use adodb.dll and its ADODB.Connection, this time I can set the objects connectiontimeout property. However, it just doesn't work. It still waits along time even though I set the connectiontimeout to 1 second. The same goes when you try the same thing in Delphi.

Anyone has any idea about this problem?

Do you want to change the timeout on the command or the connection ? Normally people want to specify the timeout on the command rather than on the connection.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

How do you check and find "SqlConnection already has connectiontimeout property as readonly and set to 15 seconds"? From what I see in VS 2005, I can edit connectiontimeout property for sqlclient.

Regarding why it still take a long time even if you set the timeout to 1 second, that's because the timeout property is enforced in different layer, specifically higer layer. If a connection is blocked or waiting in a API in lower level, it won't stop the connection until it returns from lower level. If there is still time left, higher level may try to connect again. So, the timeout is not always enforced, you should not use it for precise timing.

Saturday, February 25, 2012

Connection string to sql server

Hi I am trying to write the following connection string:

public static SqlConnection connect()
{
SqlConnection sqlConn = new SqlConnection("server=9.0.3042;database=Menu;Connection Lifetime=300");
return sqlConn;
}

I am trying to connect to a sql database using c# code. The code above is in a seperate file.

The code below is the code used to talk to the database

SqlConnection sqlConn = connection.connect();
sqlConn.Open();

SqlCommand menubar = new SqlCommand("Select * from Menu_table", sqlConn);
SqlDataAdapter dataAdapter5 = new SqlDataAdapter();
dataAdapter5.SelectCommand = menubar;
DataSet dataSet5 = new DataSet();
dataAdapter5.Fill(dataSet5);
DataTable selcartest4 = dataSet5.Tables["table"];

However the connection is just timing out like I have the wrong address set for the connection on the first bit of code posted

any heklp would be great

cheers

J

you have to give the NAME of the server not the version for the Server attribute. also you should specify the type of authentication. Referhttp://www.connectionstrings.com/?carrier=sqlserver2005 for some samples..

server=<ServerName>;database=Menu;Connection Lifetime=300

|||

Hi

Thanks for the reply, I have changed the server name to its correct IP address but its stilf ailing and I get the followin g message:

The user is not associated with a trusted SQL Server connection.

I have set it in sql server for both sql and windows authentication

is there any reason for this to happen?

cheers

Jamie

|||

If its not a production server, try restarting the SQL server and see if it helps.

|||

Hi

I have tried re-starting it as its not a production server but still failing, is there something wrong with the firewall settings maybe.

Wehn I use the stadard connection string vwd provides its OK but I wanted to set up a connection string in c#

cheers

Jamie

Friday, February 24, 2012

Connection String Problem

Hi guys,
I was trying to access the northwind database by using the following codes:

conn =new SqlConnection("data source=localhost;integrated security=true;initial catalog=Northwind");daCustomers =new SqlDataAdapter("select CustomerID, CompanyName from Customers", conn);
ds =new DataSet();
daCustomers.Fill(ds,"Customers");
When I preview the aspx, I would fail with the following error:

SQL Server does not exist or access denied.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.

Source Error:

Line 44: daCustomers = new SqlDataAdapter("select CustomerID, CompanyName from Customers", conn);Line 45: ds = new DataSet();Line 46: daCustomers.Fill(ds, "Customers");Line 47: Line 48: //create the second DataTable

But now the strange thing is when I change the data source to (local):

conn =new SqlConnection("data source=(local);integrated security=true;initial catalog=Northwind");

It works! So my question is why would localhost fail while (local) works? Shouldn't these 2 be the same? Thanks in advance.

Silvertype:

It works! So my question is why would localhost fail while (local) works? Shouldn't these 2 be the same? Thanks in advance.

I always use (local) as the server name. As far as I understand it, ifyou want to use localhost then SQL Server needs to be configured to usea TCP/IP protocol, which isn't always the case.|||

I see. Btw, how do I configure SQL Server to use TCP/IP?

|||

Silvertype:

I see. Btw, how do I configure SQL Server to use TCP/IP?


As far as I know, it's via:Start -> Programs -> Microsoft SQL Server -> Client Network Utility|||Well, it seems like TCP/IP is already enabled for my sql server. However, localhost is still not working. Any idea?|||

Silvertype:

Well, it seems like TCP/IP is already enabled for my sql server. However, localhost is still not working. Any idea?


I do not know for sure. I always use (local).

Check out this blog post from Jon Galloway for some possible further help/explanation:[tip] localhost vs. (local) in SQL|||

Ok, thanks.