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.....
public void 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)
{
throw new Exception(xe.ToString());
}
}
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/
|||
Using first technique,
this is what I get
{"Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection." }
|||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/
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....
|||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/
|||
Hello - are you still having trouble connecting?
Buck Woody
http://www.buckwoody.com
|||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
|||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
No comments:
Post a Comment