Click here to Skip to main content
15,911,360 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to connect to a db in c# but have an error in conection string how can i set it??
here is my code:
C#
string str = "Data Source=ADMIN-B19C3BADF;Initial Catalog=bazarkhodro;Integrated Security=True";
           Qconnection.ConnectionString = str;
Posted
Comments
bbirajdar 6-Dec-12 4:17am    
username ? password?
ho.kurd 27-Aug-13 18:58pm    
So What About MDF ?
f.sarikhani 6-Dec-12 4:19am    
i connect a gridview to db and copy its connection string and i dont have user name and pass in my db
Patel Shailendra 6-Dec-12 4:24am    
can you post here whats error you get.
f.sarikhani 9-Dec-12 0:17am    
Unknown connection option in connection string: initial catalog.

you can get connection string in following way also...
1. create test.udl file on ur desktop.
2. open that file
3. select ur sever name
4. select ur database
5. click on test connection (if its succeded)
6. click on finish.
7. open same file with wordpad/ notepad
8. add username and password(if you are using server authontication)
copy the connection string and pest it your config file
like

XML
<connectionStrings>
   <add name="ApplicationServices" connectionString="copy connection string here" 
    />
 </connectionStrings>
 
Share this answer
 
v2
I dont see the user name password in the connection string. Refer this website
http://www.connectionstrings.com/sql-server-2008[^]
 
Share this answer
 
C#
static string ConStr = "Data Source=ADMIN-B19C3BADF;Initial Catalog=bazarkhodro;Integrated Security=True";
SqlConnection con = new SqlConnection(ConStr);
 
Share this answer
 
First of all connect to database from server exploroer
then right click on database>properties in that You will find the exatct connection string copy and paste it in web config <connectionstring><add name="cn" connectionstring="Paste here">
and then
in common class in constructor method call the
cn=new SqlConnection(configurationManager.Connectionstrings("cn").connectionstring);
cn.open();

may be this will Help You..
hApPy cOdInG:)
 
Share this 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