Connection String

I have a database installed on my machine... I want to connect it from C# what will be the connection String...I tried something along this doesn't work.....

publicvoid OpenConnection()

{

try

{

// Create a connection object

m_connection =new SqlConnection();

// Create the connection string

m_connectString = @"data source=localhost; initial catalog = WMS_Warehouse; User ID=sa; Password =something; integrated security=SSPI; persist security info=False";

m_connection.ConnectionString = m_connectString;

// Open the Connection

m_connection.Open();

}

catch (Exception xe)

{

thrownew Exception(xe.ToString());

}

}

[920 byte] By [Harsimrat] at [2007-12-25]
# 1

Hi Harsimrat,

You should use:

m_connectString = @"data source=(local); initial catalog=WMS_Warehouse; User ID=sa; Password=something;";

If it doesn't work. Then you could use:

m_connectString = @"server=(local); database=WMS_Warehouse; user id=sa; password=something;";

Good coding,

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/

JavierLuna at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 2

Using first technique,

this is what I get

{"Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection." }

Harsimrat at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 3

Your SQL Server do permit Windows only authentication.

You should go to SQL Server properties, tab Secutiry, and check SQL Server and Windows authentication.

Good Coding!

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/

JavierLuna at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 4

Where can I find SQL Server properties...I looked in Enterprise Manager I can find anywhere to change...

Secondly, after changing what should be the connection string look like....

Harsimrat at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 5

OMG!

You open your SQL Server Enterprise Manager. You expand Microsoft SQL Servers node. You expand SQL Server Group. Finally, you right-click on your server machine node. Click Properties.

Good Coding!

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/

JavierLuna at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 6

Hello - are you still having trouble connecting?

Buck Woody

http://www.buckwoody.com

BuckWoody at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 7

Yes, I do have the same problem...

This is my connection string

Initial Catalog=WMS_Warehouse;Data Source=localhost;Integrated Security=SSPI;

and this is the error

Cannot open database requested in login 'WMS_Warehouse'. Login fails.\r\nLogin failed for user 'DELL-XP\\ASPNET'."

Can please someone suggest what to do ....

Thanks,

Harsimrat

Harsimrat at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 8

OK, the user was authenticated by SQL Server but could not be redirected to his default database because it does not exists on the server. Remove the inital catalog pattern from the connection string or subsitute the databasename with "master" the name of the master database, which aslways exists. If the error is caused by a orphanded entry for the users default database, open the user in the SQL Server MS and change his default database to an exsiting and to one where he has access to (if you don′t know one, use the master db). THis can also be accomplished by using the sp_defaultdb procedure from any TSQL command line.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

JensK.Suessmeyer at 2007-10-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...

SQL Server

Site Classified