Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created an application that takes a file and saves it into database.
Here is the code

C#
int len = FileUpload1.PostedFile.ContentLength;
byte[] pic = new byte[len];
FileUpload1.PostedFile.InputStream.Read(pic, 0, len);
cnn.Open();
cmd = new SqlCommand("insert into images values='" + pic + "'", cnn);
cmd.ExecuteNonQuery();

but when I click on upload it gives me the following error
Cannot open database "E_learning" requested by the login. The login failed.

I know it is because I have not used the uid and pwd options in database connection string. Actually I am using the windows authentication mode in sql server. There is no user created for the login through sql authentication mode, although I have created one, but it doesnt work.
Can anybody help to solve my problem?
Posted
Updated 25-Oct-11 23:48pm
v2
Comments
Amir Mahfoozi 26-Oct-11 5:47am    
try to make a connection string exactly the same as the authentication method which is used when connecting with SSMS, to resolve the problem.

1 solution

Looks your connection string is not right and it will have to be in the format of
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;


Please refer http://www.connectionstrings.com/sql-server-2005[^] for further information.

Also, its worth checking whether you are able to open the SQL server in the windows authentication mode.
 
Share this answer
 
Comments
saifullahiit 26-Oct-11 6:05am    
i have used the
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
but it still gives an error
Bala Selvanayagam 26-Oct-11 9:01am    
try this http://forums.asp.net/t/1068932.aspx/1 and looks there is an issue for ASP.net applicaiton on windows authentication...

Please do not accept the answer, if it has not resolved your problem.

Looks you have accepted the answer where as your problem is not resovled and no one else will try to give you a solution thinking that its already resolved.

If it is not resovled yet, please reject the answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900