Wednesday, January 30, 2008

How can you set your ConnectionString on your Web part

Hi Folks,

This is a tricky post,alot of question i found on the web regarding how can i put the connection string for my web part once i finished my development and i want to be work with my sharepoint site. simply add your connection string on the web.config of your web site .

web.config of your site path :

simply add the connection string section after the sharepoint key and before system.web key as follows :


{add providername="System.Data.SqlClient" connectionstring="Data Source=server;Initial Catalog=mydb;User ID=DotNetBoom;Password=DotNetBoom" name="MyConnect"}


please replace {} with <> .

Hope this helps.............

Mostafa arafa


Anonymous said...

That's very much true, but remember that for lots of settings sharepoint relies on machine.config. So before adding anything to MOSS web.config check the element and related key in machine.config.
For the connectionstring by default this connectionstring is defined in the machine.config

add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"

that referes to the local installation of SQL Server express edition regardless of it's existance.

So adding a clear line to sharepoint web.config is a very good idea.

PS: Dear Mustafa, Google sucks! This blogger doesn't let me add XML text to comments :)

Mac Daddy Enforcer said...

Thanks for the information about SharePoint and web.config files, setting up a connection string. I looked all over the net and eventually found your blog with correct code.