loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 






Quickly add and attach multiple content databases to a MOSS 2007 install

by naspinski 5/5/2008 7:00:00 PM

A detailed tutorial on how to use some borrowed/modified scripts for making this task very simple

These scripts were stolen from SharepointBlogs.com and have been modified just a little to get some different functionality, I want them to take 95% of the credit... the rest is MINE!  (Thanks guys!)

 

These scripts were almost exactly what we needed, but we needed each content database to have custom names.  So I twisted the code around a bit and here is a detailed tutorial of what we did. 

**IMPORTANT - do this ONLY after you have made your initial web application.

 

Make the Databases

  1. Make a new database named temp_db_builder
  2. Make a table in temp_db_builder with this:
    CREATE TABLE create_dbs(
    id INT NOT NULL PRIMARY KEY IDENTITY, 
    db_name VARCHAR(MAX)
    );
  3. Fill that table with the trailing end of your content db names- EX: WSS_Content_SomeSite : 'SomeSite' = trailing end
  4. Edit make_dbs.sql (from the zip below):
    1. Change @ServiceIdentity and @AppPoolIdentity to the proper accounts
    2. Change the X in WHILE @Number <= X to the number of entries you added in the create_dbs table
    3. Change @DataFile and @LogFile to the proper destinations
    4. That is all that is needed, change the other properties if your situation requires
  5. Run that file, or run the query text in SQL Server Management Studio
  6. Databases are made

 

Produce the Batch file:

  1. Edit the file make_db_batch_file.vbs (from the zip below):
    1. edit NUMBER_OF_DATABASES to the number of names you added in the create_dbs table above
    2. edit SQL_SERVER_NAME to your SQL Server
    3. for however many databases you specified in #1, add the names to dbArray(x) from 0 to NUMBER_OF_DATABASES - these HAVE TO match the names in the table create_dbs
    4. edit DBnameconv to what the prefix of the databases is
    5. edit SiteURL to your site url
  2. Copy that file to your Sharepoint Admin Server to C:\Add_ContentDB_Script\
  3. Go in to your command prompt and run cscript make_db_batch_file.vbs from the C:\Add_ContentDB_Script\
  4. Batch File is made

 

Attach Content Databases to Sharepoint

  1. On your Sharepoint admin server, run a command prompt as the Sharepoint admin account (runas /user:domain\username cmd)
  2. Navigate to C:\Add_ContentDB_Script\ and run AddDBAContentDB.bat

 

And you should be all done.



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

sharepoint | sql | vb script

Moving ASP.NET roles/membership from Test/Local to Production

by naspinski 4/3/2008 2:18:00 AM

ASP.NET roles/membership providers are incredibly simple and convenient, but if you move you site straight to a production environment (SQL Server, etc.), it's probably not going to work without a couple changes

Believe it or not, I had never needed to use ASP.NET roles in any large production environment.  But recently at work, that changed.  Everything was working great on my local machine, couldn't be smoother, but then I moved everything to our web server with a SQL 2005 backend... no worky.

 

When you enable roles in ASP.NET within VS/VWD it automatically makes an MDF that resides in your App_Data folder.  And most likely, your machine is not running full-fledged SQL, just Express.  Which is just fine, but when you migrate to the production environment, even if you bring the MDF with you and place it in your App_Data file, your roles will not work.

 

What VS is forgetting to tell you is that your membership provider is using an 'invisible' ConnectionString called 'LocalSqlServer' and that that connectionString uses SQL Express and Windows credentials to access it.  Which is why, in most cases, that that connectionString will not work in your production setting.  What you need to do is two things:

 

  1. Move your MDF to you production SQL Server instance
  2. Make sure your role provider references that instance by changing the connection string

 

This is very easy to do, and here is how you do it:

Move your MDF to your Production SQL

  1. Copy your ASPNETDB.mdf file from your App_Code folder to Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data on your SQL machine
  2. Open SQL Server Management Studio and connect to your database
  3. Right click on the 'Databases' folder in the navigation pane, click 'Attach...'
  4. Click the 'Add...' button and navigate to your ASPNETDB.mdf on that machine, click 'OK'
  5. Click 'OK'
  6. You now have it attached and ready to use, I recommend renaming it as the name will be very long (I renamed it simply ASPNETDB.mdf - I'm creative)

Make sure your program references the new database location

  1. Go into your web.config file for your program, locate the connectionStrings section
  2. Add the following 2 lines:
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="CONNECTION_STRING_TO_MEMBERSHIP_DB" providerName="System.Data.SqlClient"/>
  3. Upload and you should be all set

The important thing here is that you cleared out the 'invisible' connectionString that .Net uses and replaces it with one that is going to run off of your newly implemented database.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

asp.net | sql | tutorials

SQL Search Control for your page using asp.net :: code

by naspinski 1/30/2008 6:02:00 PM

Providing only keywords, this tool will write a simple search query, run it, and display your results; lightweight and easy to customize; in both control form, and standalone page

I was tired if writing SQL for doing simple queries on my databases, especially when they got loooong... so I ended up writing a program to do it for me.  Now this is in no way a complex search tool, but it does its job.  It does use 'LIKE' as I needed it to search text fields, but you can change that out if you want - this will get you started.

 

All you need to do to get it running is to provide 3 values: 

  1. Either your DB ConnectionString, or the name of that ConnectionString in your web.config
  2. The name of the table you wish to search
  3. The column names you want to compare to the search terms

And that is it.  The search is delimitted by [space], [comma], [semicolon], and [plus-sign] and each keyword must show up in at least one of the fields in order for the search to return results.

 

I provided both a standalone page that runs the search on itself, and a control version that consists of a user control that you can insert anywhere, and a search.aspx page that will show the results.  The control is very versatile. 

 

This is a good starting point if you want to expand on it.  I made a fully customized search at work starting with this with multiple dropdowns, fields and textboxes, all built on this basic architecture.  Play around with it and tell me what you think - I would even write a tutorial on how this thing works if anyone is interested.



Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

asp.net | c# | sql | steal some code

Agent XPs component is turned off as part of the security configuration for this server

by naspinski 1/22/2008 1:44:00 AM

If you have installed MSSQL 2005 and tried to set up a maintenance plan, this is likely the error you have encountered

Good thing is that it is extremely simple to remedy.

 

  1. Open Programs > Microsoft SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
  2. Click 'Surface Area Configuration for Services and Connections'
  3. Click 'SQL Server Agent
  4. Change 'Startup type' to Automatic
  5. Click 'Start'

 

And thats that... problem was is that default, your SQL Server agent is set to run manually, so you would have to start it every time.  Considering you are setting up a maintenance plan, you are going to want this to be automatic.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

sql